I don’t know the first thing about doing queries in CakePHP OR doing routes in CakePHP so I don’t even know how to start to find a solution for my question. Maybe you can help.
I want users to be able to go to:
http://www.domain.com/movies/1
OR
http://www.domain.com/movie-nickname
Both would access the “pages” controller, “view” action. And they should both come up with the page id = 1.
(I don’t want them to simply go to http://www.domain.com/pages/1)
Each page has a nickname for the URL, but if left blank the url will be http://www.domain.com/CATEGORY/PAGE as shown in the first example.
If the nickname is not left blank, is there a way I can do a query inside my route that says “SELECT id FROM pages WHERE nickname = ‘nickname'”
On top of this, if the nickname in the pages table is “this that”, the URL should be http://www.domain.com/this-that, meaning the hyphen needs to be replaced with spaces and THEN execute the query.
I have the route for the first URL which is:
Router::connect(
'/:category/:page',
array('controller' => 'pages', 'action' => 'view'),
array(
'pass' => array('page'),
'page' => '[0-9]+',
'category' => 'shows|music|games|books|hobbies'
)
);
Is the second option I am looking for possible?
I figured out my custom routing.