-
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Propose More Readable Panel Route and Data #23
Comments
Or, to completely remove the task part in URL, and assign it to the query string instead. ./user/page → “edit” or “read” task by default
./user/page?task=set&type=page/page → “create” task
./user/page?task=let → “delete” task The benefit is, you can run “delete” task using <form method="post">
<button name="task" type="submit" value="let">
Delete
</button>
</form> |
What if I put the user name in URL too? This will make it easier to validate current user. ./user/taufik/page → “edit” or “read” task by default
./user/taufik/page?task=set&type=page/page → “create” task
./user/taufik/page?task=let → “delete” task This would minimize the data used in panel. Less confusing. $_['root'];
$_['path'];
$_['i'];
$_['query'];
$_['hash']; |
How about removing |
@igoynawamreh the reason why I want to keep the <?php
return [
'path' => '/user',
'guard' => [
'path' => '/panel'
]
]; From the states above, expect to have |
If so then I agree to use username in the URL. |
But for some web apps I prefer not to put the user in the URL. What do you think? |
What kind of web app is that? You can always alias the route if you want: Route::set('taufik-nurrohman', function() {
// Probably put some conditional check here, to prevent
// conflict with the existing static page URL.
if ($file = File::exist(LOT . DS . 'page' . DS . 'taufik-nurrohman.page')) {
// Load static page here!
Route::fire('*', ['taufik-nurrohman']);
} else {
Route::fire('user/:user', ['taufik-nurrohman']);
}
}); |
You can also make your own control panel application if you want, by detecting if user is logged-in this way: if (Is::user()) {
require __DIR__ . DS . 'app.php';
} else {
$path = $state->x->user->guard->path ?? $state->x->user->path ?? '/user';
Guard::kick($path); // Redirect to log-in form
} Check specific user name: if (Is::user('taufik-nurrohman')) { … } |
Ummm, probably shouldn’t put the user name in URL. User name in URL is useless because internally, we take the current user name from document cookie. And to prevent conflict with public user URL, a task data in URL path is still needed anyway. ./user/asset → a user page for `@asset` user name
./user/get → a user page for `@get` user name
./user/get/asset → a panel page to retrieve the asset folder details |
Expect panel to set // `.\lot\x\panel\index.php`
if (!State::get('x.user.guard.path')) {
State::set('x.user.guard.path', '/panel');
} |
Rethinking the root data. Probably, a ---
asset:
0: []
1: []
2: []
# …
script: []
style: []
author: null
can: []
d: null
description: null
form:
lot: []
type: null
has: []
hash: null
i: null
icon: []
is: []
kick: null
lot: []
not: []
path: null
query: []
source: null
status: 200
title: null
type: null |
Internal URL builder for namespace x\panel\from {
function link($value, $key) {}
}
namespace x\panel\to {
function link($value, $key) {}
} // `http://127.0.0.1/user/get/page/article/1?type=files#main`
echo x\panel\to\link([
'd' => 'user/get',
'hash' => 'main',
'i' => 1,
'path' => 'page/article',
'query' => [
'type' => 'files'
]
]); |
if (str_ends_with($_['d'], '/get') && str_starts_with($_['type'] . '/', 'page/')) {
// Is editing a page file and is in page editor mode
} |
In Mecha 3.x.x, ---
asset:
0: []
1: []
2: []
# …
script: []
style: []
author: null
can: []
description: null
file: null
folder: null
has: []
hash: null
icon: []
is: []
kick: null
lot: []
not: []
path: null
query: []
status: 200
title: null
type: null |
All data stored in Who know, someday I will have the chance to fully convert the panel extension into React or Vue thing. |
The
$state->x->panel->path
property just adds complexity. Since panel relies on user, it would be simpler if we use the$state->x->user->path
and$state->x->user->guard->path
value as the namespace for panel routes.Currently, the route pattern contains a command stored as
/::command-name::/
in the URL. This pattern for sure makes it easy to instantly swap the commands by replacing the URL value using functions likestrtr()
andstr_replace()
due to its striking pattern. This pattern has been around since version1.x.x
of the panel, but currently, such URL patterns got quite dirty and becomes more and more difficult to be served as dynamic route patterns as more features in the panel grew.Roughly speaking, I’d like to suggest a URL pattern for panel version
3.x.x
, which is neater and will blends-in nicely with the front-end routes:Both
/user
and/panel
path will be stored in the same extension state storage (of the user extension)./user
will be stored in$state->x->user->path
and/panel
can be stored in$state->x->user->guard->path
. Due to the nature of user being independent from panel, the (secret) value of$state->x->user->guard->path
don’t have to be assigned to user, so that by default, the/panel
path will be returned as/user
, since it was the default value for the secret user log-in path when that secret value is not set (as/panel
, for example).Others
Remove
$_['/']
property. We should consider to use custom pattern in URL string that later will be replaced by the correct base panel URL. For example, we can use dummy URL protocol or fake relative URL which later will be replaced withhttp://127.0.0.1/panel/?/
in the output:Replace
$_['f']
property with$_['source']
, which its value can be either file or folder path. Ideally, the most common property name to store a file/folder path in Mecha is “path”. But, it is already used to store URL parts after the folder name, along with$_['hash']
,$_['i']
,$_['id']
, and$_['query']
properties.Alternatively, instead of removing
$_['/']
, we can rename it with$_['root']
to follow Mecha’s standard URL properties. But this likely will change the$_['path']
value, ideally, to also include the folder path. Which will make$_['id']
property becomes useless. Later,$_['root']
ideally should also include the$_['task']
part, which will make$_['task']
property becomes useless.The text was updated successfully, but these errors were encountered: