Yii Framework, User-friendly URL

January 4, 2016 27 egor

Simple example of user-friendly URL in yii framework

<?php
return array(
    //...
    'components'=>array(
        //...
        'urlManager'=>array(
            'urlFormat'=>'path',
            'showScriptName' => false,
            'rules'=>array(
                //...
                '<controller:\w+>/<id:\d+>'=>'<controller>/view',
                '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
                '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
            ),
        ),
    ),
);