Created
February 13, 2012 23:24
-
-
Save jboesch/1821407 to your computer and use it in GitHub Desktop.
cakephp 2.0 plugin re-routing problems
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
// routes.php | |
Router::connect('/animals/:action/*', array( | |
'plugin' => 'big', | |
'controller' => 'BigAnimalsController' | |
)); | |
/* | |
* Now I navigate to /animals and I look at my action attribute on my <form> tag | |
* How come my $form->create(array('controller' => 'animals')); call still outputs: | |
* /big/animals instead of /animals | |
* as the action? | |
*/ |
If it's not a user facing url I wouldn't sweat it, if it is and you're doing a full page postback you could always submit the form via ajax to mask the action url, no?
What I did to work around it was add another Router::connect to make sure /plugin/controller and /controller route to the same thing. So it works fine, I'm just a consistency whore :p
I wants all me URLz to be /controller RAWR!
A couple of reasons:
$form->create(array('controller' => 'animals'));
is incorrect. The 1st param of the$this->Form->create()
should be the Model name. Cake is simply defaulting to the controller/action it is being called from. You should do this instead:$this->Form->create('BigAnimal', array('url' => array('controller' => 'big_animals'));
- When it comes to routing you should use the underscored names for things. Instead of
BigAnimalsController
it should simply bebig_animals
. Your Router::connect should be:Router::connect('/animals/:action/*', array('plugin' => 'big', 'controller' => 'big_animals'));
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yeah, it's required, I'm just trying to hide the plugin from the URL - which works. Now instead of /plugin/mycontroller I can use /mycontroller and navigate around while hiding the plugin from the URL.
But it works up until I use a plugin view, then the url's become /plugin/mycontroller - so yeah, I'm prob doing something that most people don't do. Shrug.