0
votes

I am facing some problems in routing under cakephp there are two actions in my controller they are as below:

example.com/posts/show/show-by-day
example.com/posts/view/slug-post

I want them as:

example.com/article/show-by-day.html
example.com/article/slug-post.html

So i routes file under config file I wrote as:

Router::connect('/article/:show_by_day', array('controller' => 'posts', 'action' => 'show'), array('pass' => array('show_by_day'))); 

Router::connect('/article/:slug', array('controller' => 'posts', 'action' => 'view'), array('pass' => array('slug'))); 

its working fine when I hit the url example.com/article/show-by-day.html

but when I hit url example.com/article/slug-post.html , its again point to action show.

So how can I solve it? Many thanks!

1

1 Answers

0
votes

try this

Router::connect( '/article/show-by-day.html', 
    array(
        'controller' => 'posts',
        'action' => 'show'
    ),
    array(
        'pass' => array('show_by_day')
    )
);

Router::connect( '/article/slug-post.html', 
    array(
        'controller' => 'posts',
        'action' => 'view'
    ),
    array(
        'pass' => array('slug')
    )
);

Explanation: The first parameter of the Router::connect is the exact URL you want to match - in the original code, a : was included - which parameterized the URL instead of using exact match. The second and third paramters in Router::connect are the actual controller / action that need to be invoked along with required parameters.