Ravi Kant Singh
Ravi Kant Singh

Reputation: 45

CakePHP Routing - URL With Parameters Only

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 .

Upvotes: 0

Views: 1589

Answers (2)

Fury
Fury

Reputation: 4776

try this

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

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

Upvotes: 0

snippster
snippster

Reputation: 118

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

Upvotes: 1

Related Questions