Cakephp 如何根据cakedc插件/用户的角色使用不同的仪表板&;国际计算语言学协会

Cakephp 如何根据cakedc插件/用户的角色使用不同的仪表板&;国际计算语言学协会,cakephp,cakephp-3.x,cakedc,Cakephp,Cakephp 3.x,Cakedc,我在CakePhp应用程序中使用CakeDC用户和ACL插件。我在我的应用程序中为我的用户设置了不同的角色,我希望在登录后根据角色设置不同的仪表盘 我根据文档使用自己的表和控制器扩展插件,因此我有MyUsersController和MyUsersTable,它们覆盖插件、UsersController和UsersTable的初始文件。一切正常。我在events.php文件中创建了一个事件,其中包含: use CakeDC\Users\Controller\Component\UsersAuthC

我在CakePhp应用程序中使用CakeDC用户和ACL插件。我在我的应用程序中为我的用户设置了不同的角色,我希望在登录后根据角色设置不同的仪表盘

我根据文档使用自己的表和控制器扩展插件,因此我有MyUsersController和MyUsersTable,它们覆盖插件、UsersController和UsersTable的初始文件。一切正常。我在events.php文件中创建了一个事件,其中包含:

use CakeDC\Users\Controller\Component\UsersAuthComponent;
use Cake\Event\Event;
use Cake\Event\EventManager;

EventManager::instance()->on(
UsersAuthComponent::EVENT_AFTER_LOGIN,
['priority' => 99], 
function (Event $event) {
    if ($event->data['user']['role_id'] === 'bbcb3031-ebed-445e-8507-f9effb2de026') //the id of my client role{
        return ['plugin' => 'CakeDC/Users', 'controller' => 'MyUsers', 'action' => 'index', '_full' => true, 'prefix' => false];
    }
}
);
但似乎覆盖不起作用,因为我有一个错误:

错误:找不到CakeDC/Users.MyUsersController

在我的URL中,我有/users/my users而不是/my users,我不知道为什么。我对插件和用户控制器中包含的模板文件进行了测试,如下所示:

function (Event $event) {
 if ($event->data['user']['role_id'] === 'bbcb3031-ebed-445e-8507- 
 f9effb2de026') //the id of role{
    return ['plugin' => 'CakeDC/Users', 'controller' => 'Users', 'action' => 'profile';
 }
[
    'plugin' => null,
    'controller' => 'MyUsers',
    'action' => 'index',
    '_full' => true,
    'prefix' => false
]
它是有效的。作为客户端登录后,我的URL重定向为/profile。 有人能帮我理解吗?请告诉我,如果它不够清楚,如果它缺少的代码部分,这可能是重要的,以了解我的问题


我指定我是蛋糕初学者。

您的自定义控制器不在
CakeDC/Users
插件中,因此您必须相应地禁用
插件
键,以便生成连接到控制器的正确URL(假设您的路由设置正确),如下所示:

function (Event $event) {
 if ($event->data['user']['role_id'] === 'bbcb3031-ebed-445e-8507- 
 f9effb2de026') //the id of role{
    return ['plugin' => 'CakeDC/Users', 'controller' => 'Users', 'action' => 'profile';
 }
[
    'plugin' => null,
    'controller' => 'MyUsers',
    'action' => 'index',
    '_full' => true,
    'prefix' => false
]
例如,这将匹配默认的回退路由,生成类似于
/myusers
的URL

另见:


您的自定义控制器不在
CakeDC/Users
插件中,因此您必须相应地禁用
插件
键,以便生成连接到控制器的正确URL(假设您的路由设置正确),如下所示:

function (Event $event) {
 if ($event->data['user']['role_id'] === 'bbcb3031-ebed-445e-8507- 
 f9effb2de026') //the id of role{
    return ['plugin' => 'CakeDC/Users', 'controller' => 'Users', 'action' => 'profile';
 }
[
    'plugin' => null,
    'controller' => 'MyUsers',
    'action' => 'index',
    '_full' => true,
    'prefix' => false
]
例如,这将匹配默认的回退路由,生成类似于
/myusers
的URL

另见:


非常感谢!我真的不明白,谢谢你帮我!非常感谢!我真的不明白,谢谢你帮我!