7
Iii urlmanager does not work to get attributes
source link: https://www.codesd.com/item/iii-urlmanager-does-not-work-to-get-attributes.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Iii urlmanager does not work to get attributes
advertisements
I am new to yii. My urlmanager is not changing the get params...here is code of yiicode/protected/main.php
'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>',
),
),
view code
$this->pageTitle=Yii::app()->name;
$params=array('city'=>'london');
$route='site/index';
$ur=$this->createUrl($route,$params);
<a href="<?php echo $ur;"?> >Click here to check London hotels</a>
on clik it goes to url /yiicode/index.php/site/index?city=london instead of /yiicode/index.php/site/index/city/london
You have to add rule like this.
'rules'=>array(
'site/index/city/<city:.*?>'=>'site/index',
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK