Giter Site home page Giter Site logo

Comments (6)

mdmunir avatar mdmunir commented on September 13, 2024
  • route is special permission. Its related with application route. Why i provide this term. cause it used to check access to related route (via filter mdm\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.

Enrica-r avatar Enrica-r commented on September 13, 2024

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.

mdmunir avatar mdmunir commented on September 13, 2024

Ya, you can. But second parameter is menu_id instead menu_name.

from yii2-admin.

mdmunir avatar mdmunir commented on September 13, 2024

https://github.com/mdmsoft/yii2-admin/blob/master/docs/guide/using-menu.md#using-sparated-menu

from yii2-admin.

fedemotta avatar fedemotta commented on September 13, 2024

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.

dinhtrung avatar dinhtrung commented on September 13, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.