Yii Framework Forum: Cadvancedarbehavior Error! - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Cadvancedarbehavior Error! Error for defining many-many relationship Rate Topic: -----

#1 User is offline   Sankalp Singha 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 13-April 13

Posted 20 May 2013 - 04:18 AM

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
0

#2 User is offline   Kostas Apazidis (KonApaz) 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,380
  • Joined: 21-February 11
  • Location:Greece

Posted 20 May 2013 - 03:23 PM

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 ?
Yii is the best php framework in the world!
It is also powerful and flexible for large scale websites
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users