我在yii框架中使用这个正则表达式。但它不起作用。
'<controller>-<action>-<pagekey:['w'-]+>' => 'site/page'
我的网址是:
http://localhost:8080/site-page-contact-us
联系我们是MySQL中的一个pagekey。当我使用这个URL时,我的页面错误是:
Not found!
但当我使用这个URL时,它就起作用了。
http://localhost:8080/site-page-about
我的行动代码是:
public function actionPage($pagekey) {
$pagekey = CHtml::encode($pagekey);
if(! $model = Pages::model()->findByAttributes(array('pagekey'=>$pagekey))){
throw new CHttpException(404, 'Not found!');
}
$this->render('page', compact('model'));
}
我找到了答案。当我使用这种模式时,它就起作用了。
'site-page-<pagekey:.*>' => 'site/page'