我正在尝试像这个网站stackoverflow一样处理他们的URL。
CakePHP的工作方式如下:website/controller/action/
我想配置路由来实现这一点:
myWebSite.com/questions/(question_id)/(question)/
例如:myWebSite.com/questions/12877422/cakefp路由控制器别名//strong>
我不知道如何做这个大胆的网址部分。
在Config/routes.php 中
Router::connect('/questions/*', array('controller' => 'questions', 'action' => 'view'));
在控制器/问题控制器.php 中
查看操作获取问题id作为
public function view() {
$question_id = isset($this->request->params['pass'][0]) ? $this->request->params['pass'][0] : "";
$question = isset($this->request->params['pass'][1]) ? $this->request->params['pass'][1] : "";
if( empty($question_id) ) {
throw new NotFoundException('Could not find that question');
}
// if $question is empty then get slug from database and redirect to /question_id/question
// Get question details and set
}