I need the Tag id’s which are related to the Daytrip which is loaded in the actionUpdate.
Below you will find my code. But the problem is that the $this->tags is empty. I’ve done a print_r($this->tags) and the results is Array( ).
The relation to the Tag model is defined as follow:
'tags' => array(self::MANY_MANY, 'Tag', 'daytrip_tag(daytrip_id, tag_id)'),
Any help or suggestions are appreaciated
Controller:
public function actionUpdate()
{
$model=$this->loadModel();
Daytrip::model()->getDaytripTags();
if(isset($_POST['Daytrip']))
{
$model->attributes=$_POST['Daytrip'];
if($model->save())
$this->redirect(array('view','id'=>$model->id_daytrip));
}
$this->render('update',array(
'model'=>$model,
));
}
Model:
public function getDaytripTags()
{
$data=array();
foreach ($this->tags as $n => $tag) //$this->tags is empty
$data[] = array('id'=>$tag->id_tag, 'text'=>$tag->tag);
$this->tagIds = CJSON::encode($data);
return $this->tagIds;
}