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.
Page 1 of 1
Urlmanager And Db
#2
Posted 10 October 2012 - 11:50 AM
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
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
}
#3
Posted 10 October 2012 - 12:21 PM
Dear Friend
Make links in the following format.
For example in _view.
Modify the controller action.
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.
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.
#4
Posted 10 October 2012 - 09:10 PM
Thanks both Coksnuss and Seenivasan, i will use their examples to solve the problem. I write if i fix
Share this topic:
Page 1 of 1

Help












