I am getting the error "Attempt to assign property of non-object" on the line
$player->animalid = $animal->id;
The player record has animalid as one of the fields. The code attempts to do the following:
-
Create a new animal record (with auto_increment id key)
-
Set the player record’s animalid field with the new animal id
-
Save the player record.
if($animal->validate())
{
$player = Player::model()->findAllByPk(Yii::app()->user->id);
if (!$player)
{
throw new CHttpException(500,'Unable to read the player record. Contact the administrator.');
}
else
{
$animal->save();
$player->animalid = $animal->id;
$player->save();
$this->redirect(array('post/list'));
}
}
It must be some basic error here.
Thanks.