简体   繁体   中英

Yii url rules for main page

'urlManager'=>array(
            'class'=>'application.components.UrlManager',
            'urlSuffix'=>'/',
            'baseUrl'=>'',
            'showScriptName'=>false,
            'urlFormat'=>'path',
            'rules'=>array(
                '<language:\w{2}>'   => 'page/index',
                ''   => 'page/index',
                '<language:\w{2}>/page/<alias:.*>' => 'pages/read',
            )

link "/en/page/index" works fine
links "/" and "/en" returns the error "Unable to resolve the request" page / index ".

what is wrong with the rules

'<language:\w{2}>' => 'page/index'
'' => 'page/index',  

?

UPD:

pagesController has an action:

public function actionRead($alias){

            //some php code...

            if($model==null)
            {
                throw new CHttpException(404,'page not found...');
            }else
            {
                $this->render('read',array('model'=>(object)$model));
            }

}

Your rules that don't work are redirecting to page/index , meaning that they're going to try and access PageController.php , and within that controller, they're going to try an access actionIndex . It doesn't sound like you have either a controller PageController.php , much less an actionIndex within that controller.

You need to fix the targets of those rules to include valid controller/action combinations.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM