I’m surprised that I can’t find what I’m looking for already answered, but…
New to PHP and Yii…from a .Net background. Anyway, I’m building a Yii application and using a Yii user extension module which is pretty good, but I want to integrate that model into my existing model. For example, a user has addresses, can be a student or a teacher, etc. So I want to take the “user” that is in the module, and extend it with my own model class which has the additional relationships. Is this possible?
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'addresses' => array(self::HAS_MANY, 'Address', 'user_id'),
'coaches' => array(self::HAS_MANY, 'Coach', 'user_id'),
'students' => array(self::HAS_MANY, 'Student', 'user_id'),
);
}
[/i]
This doesn’t appear to be working. When I try to access the addresses in my AddressController like this:
[i]
public function actionIndex()
{
$user = MyUser::model()->findByPk(Yii::app()->user->id);
$model = $user->addresses;
$this->render('admin',array(
'model'=>$model,
));
}
[/i]
the code just goes off into never-never land and I don’t get anything back.
Is what I’m trying to do possible? Does anyone have any examples of this?
UserModule class of yii-user has a property named ‘relations’ where you can establish the relations to your own models without tweaking the yii-user code.