I’m learning Yii and got into url routing problem.
I have a controller as follows
class PageController extends Controller
{
public function actionIndex()
{
echo 'index';
}
public function actionGetPage($page = '')
{
echo $page;
}
and in config/main.php
'urlManager'=>array(
'urlFormat'=>'path',
'rules'=>array(
'page'=>'page/index',
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),
),
How can i set url rules so when i use http://localhost/page/About it should work and print “About”
On way to do it:
In your route configuration, you should have something like:
And define actionIndex() as follows:
Note the extra parameter required by actionView… . That will be equal to the used in the URL.