0
votes

I have two function "product" and "view" in cakephp. If any one type domainname.com/item1 then call "product" function and if domainname.com/item1/item2 then call "view" function .

item1 and item2 is dynamic content.

Router::connect('/:category', array('controller' => 'Posts', 'action' => 'product'));

Router::connect('/:category/:title', array('controller' => 'Posts', 'action' => 'view'));

I use this code in routes.php

Problem is this if I enter domainname.com/item1 then it is call view function.

please suggest me how to use url rewriting in cakephp .

2
How does Your product action looks?Bogdan Kuštan
What is you controller name?Fury
My controller is Post.Ravi Kant Singh
Problem is this if I enter domainname.com/item1 then it is call view function. - are you sure about that? The above routes do not match that behavior (demonstrate it).AD7six

2 Answers

1
votes

try to add /posts and specifie the order like this:

    Router::connect('/posts/:category/:title', 
            array('controller' => 'Posts', 'action' => 'view'),
            array(
            // order matters since this will simply map ":category" to $category in your action
            'pass' => array('category', 'title')
            )
            );

You can take a look to the doc http://book.cakephp.org/2.0/fr/development/routing.html

0
votes

try this

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

Router::connect('/:product', array('controller' => 'posts', 'action' => 'product'));