при нажатии на id получается ссылка пример user/2
Код: Выделить всё
<b><?php echo CHtml::encode($data->getAttributeLabel('id')); ?>:</b>
<?php echo CHtml::link(CHtml::encode($data->id), array('view', 'id'=>$data->id)); ?>
<br />
Код: Выделить всё
public function actionView($id)
{
$this->render('view',array(
'model'=>$this->loadModel($id),
));
}
public function loadModel($id)
{
$model=User::model()->findByPk($id);
if($model===null)
throw new CHttpException(404,'The requested page does not exist.');
return $model;
}
********************************************************
Я убрал ссылку с id и сделал ее для username получается user/view?username=arman как сделать чтобы было как у id
user/arman
Код: Выделить всё
<b><?php echo CHtml::encode($data->getAttributeLabel('username')); ?>:</b>
<?php echo CHtml::link(CHtml::encode($data->username), array('view', 'username'=>$data->username)); ?>
<br />
Код: Выделить всё
public function actionView($username)
{
$this->render('view',array(
'model'=>$this->loadModel($username),
));
}
public function loadModel($username)
{
$model=User::model()->find('username=:username', array(':username'=>$username));
if($model===null)
throw new CHttpException(404,'The requested page does not exist.');
return $model;
}