Saturday, April 6, 2013

Yii customizing the display of url parameters

Add the following rule to your main.php rules array:
'product/<id:[A-Z0-9]+>'=>'site/product',
 
 
You can then get the value by:
$id = Yii::app()->getRequest()->getQuery('id');

$this->createUrl('product',array('id'=>100));
 
 

<?php $this->widget('zii.widgets.CMenu',array(
	'items'=>array(
		array('label'=>'Product 10', 'url'=>array('/product', 'id' => 20 )),
		array('label'=>'About', 'url'=>array('/site/page', 'view'=>'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)
	),
)); ?> 
 
 
echo $this->createUrl('post/read',array('id'=>$id))."<BR>";
echo $this->createUrl('post/read',array('id'=>$id, 'title' => "New post title")); 

'post/<id:\d+>/<title>'=>'post/read',
'post/<id:\d+>'=>'post/read' 

No comments:

Post a Comment