Skip to content

Instantly share code, notes, and snippets.

@evercode1
Created December 31, 2014 08:34
Show Gist options
  • Save evercode1/3a4fce16a07ca997fb39 to your computer and use it in GitHub Desktop.
Save evercode1/3a4fce16a07ca997fb39 to your computer and use it in GitHub Desktop.
Profile Relations Chap 5
/**
* @return \yii\db\ActiveQuery
*/
public function getGenderName()
{
return $this->gender->gender_name;
}
/**
* get list of genders for dropdown
*/
public static function getGenderList()
{
$droptions = Gender::find()->asArray()->all();
return ArrayHelper::map($droptions, 'id', 'gender_name');
}
/**
* @return \yii\db\ActiveQuery
*/
public function getUser()
{
return $this->hasOne(User::className(), ['id' => 'user_id']);
}
/**
* @get Username
*/
public function getUsername()
{
return $this->user->username;
}
/**
* @getUserId
*/
public function getUserId()
{
return $this->user ? $this->user->id : 'none';
}
/**
* @getUserLink
*/
public function getUserLink()
{
$url = Url::to(['user/view', 'id'=>$this->UserId]);
$options = [];
return Html::a($this->getUserName(), $url, $options);
}
/**
* @getProfileLink
*/
public function getProfileIdLink()
{
$url = Url::to(['profile/update', 'id'=>$this->id]);
$options = [];
return Html::a($this->id, $url, $options);
}
@box2424
Copy link

box2424 commented Apr 8, 2015

for getUserLink() and getProfileIdLink() shouldn't the second argument for the 'Url::to' method be 'id' => $this->userId in both cases (syntax for magic get method to return the current user id)??

@Carsak
Copy link

Carsak commented May 23, 2015

Anybody here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment