I'm running into a problem related to caching, plugins and duplicate model names in Cake 2.0. My application has several controllers containing only actions for public use (view, index and equivalents). The data is managed by a CMS which is added as a plugin, some names of the plugin's controller are the same.
For example, I have a PostsController in my application and a PostsController for the plugin. The plugin controller extends PluginAppController
and the public controller extends AppController
as per the manual. As soon as caching is kicked in (by setting debug
to 0
) the problems start. Cake tries to access a non-existing add
action in the controller which extends AppController
and the public application tries to access methods from the PluginAppController
.
I don't understand why Cake would do this and it creates all kinds of errors (blank pages, lost sessions) which aren't logged properly as well. Everything was working well while the app still ran on Cake 1.3 and also in 2.0 production mode.
The file cake_core_file_map
in the /tmp/cache/persistent/
directory seems to be causing the issue. As soon as I remove this and reload either of the views, it renders correctly. So the procedure is as follows:
- Load
http://www.example.com/admin/posts
successfully; - Load
http://www.example.com/posts
(it fails to render); - Clear the cache (or just cake_core_file_map);
- Load
http://www.example.com/posts
successfully; - Load
http://www.example.com/admin/posts
(which now fails to load properly).
My guess is Cake fails to save the correct references to the plugin and main application paths in cake_core_file_map
, but I have no clue how to force Cake to behave nicely in that regard.
Does anybody know how to stop Cake from confusing the plugin's controllers with the other ones with duplicate names?
EDIT
This issue might be related to a bug in Cake, as this report mentions similar problems and cake_core_file_map
as well. The fix mentioned here doesn't work unfortunately.
EDIT 2
There is indeed some custom routing going on, which was working normally in Cake 1.3. This is from routes.php
:
Router::connect('/plugin_name', array('plugin' => 'plugin_name', 'controller' => 'users', 'action' => 'login'));
Router::connect('/admin/*', array('plugin' => 'plugin_name', 'controller' => 'posts', 'action' => 'index'));