andresmc
(A Medrano Cruz)
October 10, 2012, 4:40pm
1
I need your help, I want to change the url of the pages,
I have this:
crm/index.php/contact/view/1
1 represents the id of the contact stored in the database, what I need is to simply display the name of the contact with the respective id:
John Doe
is assumed that the ID of John Doe is 1.
I appreciate your help.
Coksnuss
(Schanz15)
October 10, 2012, 4:50pm
2
Hey Andres… What exactly are you trying to archive?
You said that you want to change the url of the pages - but you only provided the current schema you have - not the one you want.
Assuming you have setup your environment like described in the guide you just need to retrieve the specific row from the database.
protected/controllers/ContactController.php
public function actionView($id)
{
echo Contact::model()->findByPk($id)->name; // John Doe
}
seenivasan
(Chellamnivas)
October 10, 2012, 5:21pm
3
Dear Friend
Make links in the following format.
For example in _view.
<b><?php echo CHtml::encode($data->getAttributeLabel('id')); ?>:</b>
<?php echo CHtml::link(CHtml::encode($data->id), array('view', 'name'=>$data->username)); ?>
Modify the controller action.
public function actionView($name)
{
$model=User::model()->findByAttributes(array('username'=>$name));
$this->render('view',array(
'model'=>$model,
));
}
In UrlManager change the format to path
When the user/contact name is not unique, we can face problems.
I hope there are better solutions than this.
Regards.
andresmc
(A Medrano Cruz)
October 11, 2012, 2:10am
4
Thanks both Coksnuss and Seenivasan, i will use their examples to solve the problem. I write if i fix