我已經在我看來,下面的鏈接,通過傳遞日期和後段塞調用後:CakePHP中使用日期路線
<?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']; ?><
正如你可以看到我用的strtotime做在URL中使用的日期時間更漂亮。
我實際上並沒有在控制器中使用日期來將帖子從數據庫中拉出來,只是slu so一聲,所以無關緊要。
但問題是,由於日期有/
,路由器會感到困惑,並認爲它是url的兩個單獨部分。我該如何解決?
我的路線如下:
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')
));
我喜歡獨立Date參數的方法 – mark
是的,我喜歡這種方法,以及:)謝謝 – Cameron