Created
December 31, 2014 08:34
-
-
Save evercode1/3a4fce16a07ca997fb39 to your computer and use it in GitHub Desktop.
Profile Relations Chap 5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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)??