-
-
Save jboesch/1821407 to your computer and use it in GitHub Desktop.
<? | |
// 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? | |
*/ |
Yeah, it's line 386 in FormHelper.php.
$plugin = null;
if ($this->plugin) {
$plugin = Inflector::underscore($this->plugin);
}
It's grabbing $this->plugin that get's automatically set in the controller.
I'm wondering if this would be considered a bug or if I'm just trying to do something out of the ordinary.
What's the plugin do in this instance? Required for what you are doing?
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.
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'));
I haven't done cake since 1.3(ish) but it seems to me the default behavior is to include the plugin as part of the path in the emitted form element from your form helper?