Comments (6)
route
is special permission. Its related with application route. Why i provide this term. cause it used to check access to related route (via filtermdm\admin\components\AccessControl
) :D./foo/bar/*
mean has access to all route under (with prefix)foo/bar/
.- Menu only work with route.
- Litle different is, we can check access route via
mdm\admin\components\AccessControl
. E.g, if you access to 'site/index',AccessControl
will check is user can access 'site/index'. Internaly, he will do
$user->can('site/index');
$user->can('site/*');
$user->can('*');
- Ya, you can also have hierarchical menu.
- You can add extra params to route. But it static. You can create route with format `site/page&view=about'.
I hope you understand my word, i am not god describe something.
from yii2-admin.
Thank you very much for your explanations. Now it's more clear for me. I will try it. Sometimes I have difficulties to describe something too.
So probably I wrote question about the menue not clear. I know that you menue table does support hierarchies (childs). My question was. How can I handle more then one menu? If I enter first level (->parent id === null) I will get all entries for a user. If my application has a main menue and sometime sub menues I should be able to name it. Then while using it I should be possible to name it also like MenuHelper::getAssignedMenu(Yii::$app->user->id, 'main menue')
. Do you understand what I mean?
from yii2-admin.
Ya, you can. But second parameter is menu_id
instead menu_name
.
from yii2-admin.
https://github.com/mdmsoft/yii2-admin/blob/master/docs/guide/using-menu.md#using-sparated-menu
from yii2-admin.
I tried to use menu
but it doesn't fit my needs. Some items in the web menu that I am developing are just text labels and are being used just to group items with an expand JS functionality. I need to show items expanded and selected when the user is in certain controller or action. I also have to show only the allowed routes to the user.
See this item in example:
'/document/*,/document/index,/document/create,/document/view,/document/update'=>['text'=>Yii::t('app','Documents'),'url'=>'#','icon'=>'fa fa-file-text fa-lg',
'items' => [
'/document/index'=>['text'=>Yii::t('app','Manage'),'url'=>Url::toRoute('/document/index')],
'/document/create'=>['text'=>Yii::t('app','Create'),'url'=>Url::toRoute('/document/create')],
],
],
I was trying to move this hardcoded array to @mdmunir menu in the db and linking it to the routes but I think it is not possible. Because:
1- I found no way to add menu items without links.
2- Also there is a problem with the permission check. Maybe an user has access to document/*
and it won't see the items. That is why I am creating the long array index. To make the check later.
3- It would be great an automatic menu generator. I have more or less 100 routes.
Waiting for your comments!
from yii2-admin.
I have difficulty in using Yii::$app->user->can() to check for permission.
For example, got this menu items:
['label' => Yii::t('app', 'User Management'), 'url'=>['/user/admin/index'], 'visible' => \Yii::$app->user->can('/user/admin/index')],
['label' => Yii::t('app', 'Logout'), 'url'=>['/user/security/logout']],
If the logged got route '/user/admin/' or '/user/', he still cannot see the menu item.
He must got exactly '/user/admin/index' to see the menu.
I think we can add the following way to override can()
from yii/web/user
:
Create another class in the app:
namespace app\components\web;
use yii\web\User as BaseUser;
use Yii;
class User extends BaseUser
{
public function can($permissionName, $params = [], $allowCaching = true)
{
Yii::trace("Checking permission of $permissionName", "can");
$access = false;
if ($access = parent::can($permissionName, $params, $allowCaching))
return $access;
else {
do {
Yii::trace("Checking extra permission of $permissionName", "can");
$permissionName = substr($permissionName, 0, strrpos($permissionName, '/'));
} while (!($access = parent::can($permissionName . '/*', $params, $allowCaching)) && ($permissionName));
return $access;
}
}
}
Then in your app config:
'components' => [
....
'user' => [
'class' => 'app\components\web\User',
'identityClass' => 'dektrium\user\models\User',
'enableAutoLogin' => true,
],
...
]
Any comments? How about adding this feature into the module?
from yii2-admin.
Related Issues (20)
- Use own login view HOT 2
- /admin get Class 'app\models\UserSearch' not found
- Error: Call to undefined method app\models\User::setInstance()
- is it possible to add route with parameter ?
- Access and Assignment issue with REST API
- bad request 400
- Problem With Routing URL HOT 1
- License inconsistent
- Support untuk PHP 8.1 HOT 1
- Can not instantiate when controller file is abstract or interface class
- Access control on master HOT 2
- Syntax error on file mdmsoft/yii2-admin/components/AccessControl.php HOT 3
- Menu with subitems didn't show up on Bootstrap5 HOT 1
- I keep getting errors when creating roles and keeping rules ampty HOT 1
- how to filter menu but using native navbar ?
- Clean Invalid routes (Permissions) HOT 1
- how about change the usernameField expression as a Column expression HOT 1
- can not auth HOT 1
- Error Class "yii\bootstrap\ActiveForm" not found in view mdmsoft\yii2-admin\views\user\login.php HOT 1
- migration on web HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from yii2-admin.