Static Pages in Yii Problem

'urlManager'=>array(
    'urlFormat'=>'path',
    'rules'=>array(
        '<view>' => array('site/page/view/'),
        '<controller:\w+>/<id:\d+>'=>'<controller>/view',
        '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
        '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
        //'index' => array('site/index'),
    ),
),

I currently have this in the main.php file.

The problem is that when I browse /index.php/index, I show the index page in the pages folder, but when I get to /index.php/about, I still get the index.php file on the pages folder.

+3
source share
2 answers
'urlManager'=>array(
    'urlFormat'=>'path',
    'rules'=>array(
        '<controller:\w+>/<id:\d+>'=>'<controller>/view',
        '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
        '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
        //'index' => array('site/index'),
        '<view>' => array('site/page/view/'),
    ),
),

It should be like this:

+2
source

Now the rule should be (at least in version 1.1.12)

'<view:\w+>' => 'site/page', 

This code will provide $ _GET ['view'] SiteController :: actionPage, for example. http://example.com/test will set $ _GET ['view'] = 'test'

+1
source

Source: https://habr.com/ru/post/1781599/


All Articles