Yii Framework Forum: Accessing owner of relational model - Yii Framework Forum

Jump to content

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

Accessing owner of relational model Rate Topic: -----

#1 User is offline   Y!! 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 978
  • Joined: 18-June 09

Posted 12 May 2010 - 02:13 PM

I want to do something like this

$user->profile->getUrl();


instead of

$user->getProfileUrl();


To return (generate) the correct profile url, I need the id or even more attributes of the actual user model within the profile model. Is this possible already in some way?

This is how I would like to do it:

public function getUrl()
{
   return Yii::app()->createUrl('user/profile', array('id' => $this->owner->id));
}

0

#2 User is offline   Onman 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 175
  • Joined: 26-December 09
  • Location:The Netherlands

Posted 12 May 2010 - 03:46 PM

I guess you can do it like you wrote. That should work.
0

#3 User is offline   Theill11 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 51
  • Joined: 03-March 10
  • Location:@ localhost

Posted 12 May 2010 - 04:27 PM

This would work if you defined the relation "owner".

CActiveRecord does not have a owner property and it would not make sense, because models could have several owners (BELONGS_TO relationships), which i assume you are refering to?
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