0

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 .

4
  • How does Your product action looks? Commented Aug 26, 2015 at 10:43
  • What is you controller name? Commented Aug 27, 2015 at 9:16
  • My controller is Post. Commented Aug 27, 2015 at 10:23
  • 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). Commented Aug 28, 2015 at 8:31

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

we do not put any prefix in url like "posts"
0

try this

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

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

6 Comments

Same problem is there. At a time only one router are work .
What do you mean? This does what you have asked. If you go to item1 domainname.com/item1 otherwise if you go to item1/item2 goes to domainname.com/item1/item2
What is you controller name?
item1 and item2 is dynamic content if i enter domainname.com/asus-zenfone-2 it goes to product page and if domainname.com/mobile/samsung it goes view page
in this mobile is fix but somr time it is mobile or tab-late or somthing else .it is dynamic content
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.