Jump to content

Archived

This topic is now archived and is closed to further replies.

CrimpJiggler

CakePHP - Routing messing up links

Recommended Posts

In my routes.php file, I added this:

Router::connect('/Compounds/:action/*',array('controller' =>  'Substances'));
Router::connect('/Preparations/:action/*',array('controller' => 'Substances'));
Router::connect('/Formulations/:action/*',array('controller' => 'Substances'));
Router::connect('/Plants/:action/*',array('controller' => 'Substances'));

and now, the links generated by Paginator all point to Compounds, even when thats not the model which has been loaded with $this->Paginator->paginate($model);

 

If I change the order, so its:

Router::connect('/Plants/:action/*',array('controller' => 'Substances'));
Router::connect('/Compounds/:action/*',array('controller' =>  'Substances'));
Router::connect('/Preparations/:action/*',array('controller' => 'Substances'));
Router::connect('/Formulations/:action/*',array('controller' => 'Substances'));

then all the paginator links point to Plants. The same problem occurs when I redirect to $this->redirect(array('action' => 'index'));

without specifying the controller. So it seems the routes page is altering the links which don't specify a controller. This wouldn't be a problem (on the contrary, it'd be helpful) if it would add the correct controller to the links, I don't know why its adding Compounds to every link.

Share this post


Link to post
Share on other sites

I fixed the pagination issue by adding this:

$this->Paginator->options(array(
    'url' => array(
        'controller' => correct_value
    )
));

to the view page, where correct_value is the pseudocontroller value that should appear in the link URL. 

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.