I have the following link in my view which calls a post by passing the date and the slug of the post:
<?php echo $this->Html->link($post['Post']['title'],
array('controller' => 'posts', 'action' => 'view', 'date'=>date('Y/m', strtotime($post['Post']['datetime'])), 'slug'=> $post['Post']['slug'])); ?></h2>
<h4><?php echo $post['Post']['datetime']; ?><
As you can see I use strtotime to make the datetime prettier for use in the URL.
I don’t actually use the date in the controller for pulling the post out of the database, just the slug so it doesn’t matter too much.
The problem however is that because the date has a / in it, the router gets confused and thinks it’s two seperate parts of the url. How do I fix this?
My route is as follows:
Router::connect('/news/:date/:slug',
array('controller' => 'posts', 'action' => 'view'),
array(
//'date' => '[A-Za-z0-9\._]+',
'slug' => '[A-Za-z0-9\._]+',
'pass' => array('date', 'slug')
));
Are you using cake 2?? if you do, you can try this, as book says:
But I guess you should pass slug first.
Otherwise you can change your
/by-(or anything else). But, if you want to keep them, you can declare the date as separated parameters in your route, something like: