Yii Framework Forum: Urlmanager And Db - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Urlmanager And Db Rate Topic: -----

#1 User is offline   Andres 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 16
  • Joined: 18-July 11

Posted 10 October 2012 - 11:40 AM

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.
0

#2 User is offline   Coksnuss 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 140
  • Joined: 14-May 09

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
public function actionView($id)
{
   echo Contact::model()->findByPk($id)->name; // John Doe
}

0

#3 User is offline   seenivasan 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 620
  • Joined: 17-June 12
  • Location:Chennai,TamilNadu,India.

Posted 10 October 2012 - 12:21 PM

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.
0

#4 User is offline   Andres 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 16
  • Joined: 18-July 11

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 :rolleyes:
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users