Skip to content

Instantly share code, notes, and snippets.

@jboesch
Created February 13, 2012 23:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jboesch/1821407 to your computer and use it in GitHub Desktop.
Save jboesch/1821407 to your computer and use it in GitHub Desktop.
cakephp 2.0 plugin re-routing problems
<?
// 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?
*/
@shama
Copy link

shama commented Feb 16, 2012

A couple of reasons:

  1. $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'));
  2. When it comes to routing you should use the underscored names for things. Instead of BigAnimalsController it should simply be big_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