Urlmanager And Db

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.

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

}



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.

Thanks both Coksnuss and Seenivasan, i will use their examples to solve the problem. I write if i fix :rolleyes: