Referring To Routes Of /site/page Urls?

Using Yii 1.1.12. I’m trying to create friendly urls for static pages. So for example I want “/about” instead of “/site/page?view=about”.

Following the example in How to remove index.php from URL, I added the following url rule:




'urlManager'=>array(

    'urlFormat'=>'path',

                'showScriptName'=>false,

    'rules'=>array(

        ...

        '<action:(contact|index|login|logout)>' => 'site/<action>',

        '<view:(about)>' => 'site/page',

        ...

    ),



this works. However I’m new to MVC routing so what’s not clear to me is now when I want to create a link to this page in other code, how should I refer to the route? For example in my main.php layout file I have this menu:




<div id="mainmenu">

    <?php $this->widget('zii.widgets.CMenu',array(

        'items'=>array(

            array('label'=>'Home', 'url'=>array('/site/index')),

            //array('label'=>'About', 'url'=>array('/site/page', 'view'=>'about')),

            //array('label'=>'About', 'url'=>array('/about')),

            array('label'=>'Contact', 'url'=>array('/site/contact')),

            array('label'=>'Login', 'url'=>array('/site/login'), 'visible'=>Yii::app()->user->isGuest),

            array('label'=>'Logout ('.Yii::app()->user->name.')', 'url'=>array('/site/logout'), 'visible'=>!Yii::app()->user->isGuest)

        ),

    )); ?>

</div><!-- mainmenu -->



Both of the commented out "About" menu items in the above menu work and will end up creating a link to "/about". However which is the best practice to use, the "true" route or the aliased route?

Hi, and welcome to the forum.

You should definitely use the 1st one.

You are creating the url using the url manager in the 1st one. It will continue to work even if you have made some changes to the url manager’s configuration.

But in the 2nd one, you are manually imitating only the result under the current rule. If you have changed the url manager’s settings, then it won’t work any more.

Hi makes sense thank you