Search code examples
cakephppluginscakephp-3.x

Cakephp 3 problems accesing non plugin links from plugin pages


I have a cakephp app and I created a plugin based on cakephp 3.8 official documentation. Everything is good, I can access links like:

project.local/plugin/plugin-tests/

. The problem is that after I access that plugin link, all my links are updated with the plugin name. Eg: project.local/users/ is transformed into project.local/plugin/users/.


Solution

  • The values for plugin, prefix, controller and action are being persisted by default, meaning that if you don't specify them explicitly in your URL arrays, they inherit the value of the current context.

    If you want your links to always point to a non-plugin target, make sure to set null for it, likewise set false for the prefix (not null), ie:

    [
        'plugin' => null, // break out of plugin contexts
        'prefix' => false, // break out of prefix contexts
        'controller' => 'Users',
        'action' => 'index',
    ]
    

    See also