Sunday, March 13, 2022

[FIXED] Cakephp 3 problems accesing non plugin links from plugin pages

Issue

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



Answered By - ndm

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.