Troubles creating a new cakephp plugin in a working application + wrong usage of requestAction

StackOverflow https://stackoverflow.com/questions/23658749

  •  22-07-2023
  •  | 
  •  

Pergunta

I'm trying to create a new plugin for my (already working) cakephp application. I have followed the manual with the exact same data (ContactManager plugin, Contacts controller etc.), but when I try to load it by using its url (example.com/contact_manager/contacts/index), cakephp complains that LanguageController (which is called with a requestAction from my layout file) is not in my plugin path. It shouldn't be there indeed, since it is an application controller...

What am I doing wrong?

I'm not posting code because I used exactly the same code as the cakephp manual, here: http://book.cakephp.org/2.0/en/plugins.html

Foi útil?

Solução

The current plugin and prefix persist

If you do the following:

$this->requestAction(array(
    'controller' => 'x', 
    'action' => 'y'
));

And the current request is in your app, you're requesting the equivalent of the url:

/x/y

If you are in your foo plugin, the same code is the equivalent of the url:

/foo/x/y

To always request something from your app, define with a falsey value the key 'plugin':

$this->requestAction(array(
    'controller' => 'x', 
    'action' => 'y', 
    'plugin' => false
));

OR use a string url.

You're doing something odd

CakePHP complains that LanguageController (which is called with a requestAction from my layout file)

It's not normal to use requestAction like that - you should send information to the view (meaning the view layer - the view class, view files, layouts, elements, helpers). You don't ask for information in the view. Writing code like that is a recipe for problems. For example if the language controller throws an exception - all urls will be an error.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top