Duplicate controller names from different plugins

末鹿安然 提交于 2019-12-07 13:24:11

问题


I have a question regarding the file loading system from Cakephp2.3.

I have two plugins - let's call them "Contacts" and "Managers", loaded like this:

CakePlugin::load('Contacts');
CakePlugin::load('Managers');

Each of them has a controller called "DashboardController.php" with an index() action.

When I try to access the dashboard page for "Contacts", sometimes I see the following error:

Error: Class "ManagersAppController" not found

even though the url looks like this:

http://mysite.com/contacts/dashboard

I read that Cakephp2.3 doesn't support namespaces and this might happen because I have two php classes (DashboardController.php) with the same name. At the same time, I know that Cake should map the plugin name first, so it should be able to handle duplicate file names.

Do you have any idea why I'm seeing this random error?

Thanks for your help.


回答1:


I just found the answer from the guys the developed CakePHP. Indeed, you can't have two controllers or models with the same name, even though they are located in different plugins.

This happens only in CakePHP2.x and I quote:

This is a known limitation of Cake2.x and the lazy loading approach using App::uses()

You can see my question and their answer here: http://cakephp.lighthouseapp.com/projects/42648-cakephp/tickets/3558-loading-file-from-a-different-plugin

The solution is to rename the controllers/models with conflicting names and/or name all controllers and models from a plugin using the plugin name (ex. DashboardController.php will become ContactsDashboardController.php)



来源:https://stackoverflow.com/questions/14460626/duplicate-controller-names-from-different-plugins

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!