Cadvancedarbehavior Error!

Hi there,

I have recently started in Yii and I am now stuck in this problem,

I am making a blog system in yii and I have a "Post" table and a "Tag" table which is a many-many relatioship,

The relation defined in my Post.php model class is :


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(

			'comments' => array(self::HAS_MANY, 'Comment', 'tbl_post_id'),

			'author' => array(self::BELONGS_TO, 'User', 'tbl_user_id'),

			'tagsRelation' => array(self::MANY_MANY, 'Tags', 'tbl_tags_has_tbl_post(tbl_post_id, tbl_tags_id)'),

			'commentCount' => array(self::STAT,'Comment','tbl_post_id'), // this shall count the number of comments present

		);

	}

And the relation defined in my Tags.php model is :


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(

			'posts' => array(self::MANY_MANY, 'Post', 'tbl_tags_has_tbl_post(tbl_tags_id, tbl_post_id)'),

		);

	}

So after this I wanted to save the tags from the PostCreate method and also update the many-to-many relation table in my DB, hence I installed the CAdvancedArBehavior extension.

After this I modified my Post controller actionCreate() in this way :


public function actionCreate()

	{

		$model=new Post;

		$tags = new Tags; // This is for initializing the second model




		$model->tbl_user_id = Yii::app()->user->id;


		// Uncomment the following line if AJAX validation is needed

		// $this->performAjaxValidation($model);


		if(isset($_POST['Post'],$_POST['Tags']))

		{

			$model->attributes=$_POST['Post'];

			$tags->attributes = $_POST['Tags'];

			$valid=$model->validate();

        	$valid=$tags->validate() && $valid;

			

			$model->tagsRelation = Tags::model()->findAll();

			$model->save();

			

			

			


        	if($valid)

        {

            // use false parameter to disable validation

            

            $tags->save(false);

            // ...redirect to another page

            // 

  

        }

			if($model->save())

				$this->redirect(array('view','id'=>$model->id));

		}


		$this->render('create',array(

			'model'=>$model,

			'tags' =>$tags,

		));

	}



However, when I try to save my post this is the error that I get.


Property "Tags.tbl_tags_id" is not defined. 

I dont know why it is giving me this error, I followed exactly as the extension page said. (CAdvancedAR)

Please guide me as to where am I getting it all wrong.

Regards,

Sankalp Singha

Hi Sancalp

I don’t use CAdvancedAR yet. But could you post your view file? How get the multiple tags (on view) ?

$_POST[‘Tags’] is one ore more tags ?