Using regular expressions in URL rules
One of the hidden features of the Yii URL router is that you can use regular expressions that are pretty powerful when it comes to strings handling.
Getting ready
Create a fresh Yii application using
yiic webappas described in the official guide and find yourprotected/config/main.phpfile. It should contain the following:// application components 'components'=>array( … // uncomment the following to enable URLs in path-format /* '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>', ), ),Delete everything from
rulesas we are going to start from scratch.In your
protected/controllersdirectory, createPostController.phpwith...