I’m trying to insert a record in the background using an action. For instance, I am looking at a content type and want to insert a favorite for it. I am trying to pass enough information from the current content record to an action method in the UserFavoriteController. I can’t get the structure right for the multiple params.
I need to pass $title, $description, $what (what content table), $item (the id of the content item).
Here’s the code in the content view file:
<?php
$title=$model->formatted_name;
$description=$model->description;
$what='contact';
$item=$model->id;
$details=array('title'=>$title, 'description'=>$description, 'what'=>$what, 'item'=>$item);
$where='/hawkwebapp/index.php?r=userfavorite/add&details='.$details;
?>
<a href=<?php echo $where;?> >
<image src="/hawkwebapp/assets/hawk/icons/googlePlus/color18/star.png" alt="Add Favorite" align="right" />
</a>
Here’s the code from the action method in the UserFavoriteController:
public function actionAdd($details)
{
$title=$details->title;
$description=$details->description;
$what=$details->what;
$item=$details->item;
$favorite=new UserFavorite;
$favorite->user_id=Yii::app()->user->id;
$favorite->title=$title;
$favorite->description=$description;
$favorite->what=$what;
$favorite->where='mainDB';
$favorite->item_id=$item;
$favorite->behavior='';
$favorite->weight=1;
$favorite->status='Active';
$favorite->insert_datetime=time();
$favorite->last_edit_datetime=time();
$favorite->insert_datetime_utc=$favorite->insert_datetime;
$favorite->last_edit_datetime_utc=$favorite->last_edit_datetime;
$favorite->save();
$this->render('create',array(
'model'=>$favorite,
));
$this->redirect(Yii::app()->user->returnURL);
}
The php error is: Trying to get property of non-object
This happens at the first line accessing a param:
$title=$details->title;
Everything is new to me now, so I can’t see where the problem is.
Can you?
Thanks,
Alex