Yii Framework Forum: Taggable Behaviour - Yii Framework Forum

Jump to content

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

Taggable Behaviour This extension allows active record model to manage tags. Rate Topic: -----

#21 User is online   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 2,651
  • Joined: 17-January 09
  • Location:Russia

Posted 04 March 2011 - 05:01 AM

That means you don't have $model->tags. How you've attached behavior?
0

#22 User is offline   psikocrisis 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 38
  • Joined: 15-July 10
  • Location:Madrid / Sardinia

Posted 04 March 2011 - 05:08 AM

View Postsamdark, on 04 March 2011 - 05:01 AM, said:

That means you don't have $model->tags. How you've attached behavior?


I have debugged this, $model->tags returns an Array of Tag objects...

In my model I have:
public function behaviors() {
		return array(
				'tags' => array(
						'class' => 'application.extensions.taggable.ETaggableBehavior',
						'tagTable' => 'Tag',
						'tagBindingTable' => 'Event_has_Tag',
						'tagBindingTableTagId' => 'tag_id',
						'modelTableFk' => 'event_id',
						'tagTablePk' => 'id',
						'tagTableName' => 'name',
						'scope' => array(
								'condition' => 'public = 1 OR user_id ='. Yii::app()->user->id,
						),
						'insertValues' => array(
								'user_id' => Yii::app()->user->id,
						),
				)
		);
}

0

#23 User is online   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 2,651
  • Joined: 17-January 09
  • Location:Russia

Posted 04 March 2011 - 05:13 AM

Looks like you have same named AR relation.
1

#24 User is offline   psikocrisis 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 38
  • Joined: 15-July 10
  • Location:Madrid / Sardinia

Posted 04 March 2011 - 05:51 AM

View Postsamdark, on 04 March 2011 - 05:13 AM, said:

Looks like you have same named AR relation.


:lol:

Thanks man!!!
0

#25 User is offline   dhaos 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 10-August 11

Posted 10 August 2011 - 01:58 AM

the tag_entity to record tag_id, entity_id and entity_type, that make tag fits any other entity(table)
and I've modified class for our use, by adding variable named 'insertBidingValues' and related snappet
but 'insertValues' is not work
	public function behaviors(){
		return array(
			'tags'=>array(
				'class'=>'ext.yiiext.behaviors.model.taggable.EARTaggableBehavior',
				'tagTable'=>'tag',
				'tagBindingTable'=>'tag_entity',
				'modelTableFk'=>'entity_id',
				'tagTablePk'=>'id',
				'tagTableName'=>'title',
				'tagBindingTableTagId'=>'tag_id',
				'cacheID'=>'tag_cache',
				'createTagsAutomatically'=>true,
				'insertValues'=>array(
					'parent_id'=>0
				),
				'insertBindingValues'=>array(
					'entity_type'=>'article'
				),
			)
		);
	}

0

#26 User is offline   julianm 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 04-January 12

Posted 07 April 2012 - 04:08 PM

Is this still active? Anybody using it successfully? I am trying to download the code but seems only source code is available and no a release version yet. Anybody can advice? I am looking for an extension or behavior for Yii that let me manage Tags as you exposed. Thanks.
0

#27 User is online   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 2,651
  • Joined: 17-January 09
  • Location:Russia

Posted 23 April 2012 - 04:55 AM

It's alive and kicking :)

http://yiiext.github...vior/index.html
0

#28 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 23 April 2012 - 05:33 AM

I've used it successfully in several projects. :)
"Less noise - more signal"
0

#29 User is offline   NCS_One 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 35
  • Joined: 24-August 11

Posted 12 June 2012 - 01:04 PM

Hi,

Thanks for the great extension.

I'm trying to use it but getting a error.

// Post.php

  public function behaviors()
  {
    return array(
      'tags-with-model'=>array(
        'class'=>'ext.taggable.EARTaggableBehavior',
        'tagTable'=>'tag',
        'tagModel'=>'Tag',
        'tagBindingTable'=>'post_tag',
        'modelTableFk'=>'post_id',
        'tagTablePk'=>'id',
        'tagTableName'=>'name',
        'tagTableCount'=>'count',
        'tagBindingTableTagId'=>'tag_id',
      ),
    );
  }



// PostController.php

  public function actionCreate()
  {
    ...
    try
    {
      $model->setTags('test')->save('false');
      ...
    ...
  }


I'm using Postgresql 8.4
// tag.sql

DROP TABLE IF EXISTS tag CASCADE;
DROP TABLE IF EXISTS review_tag CASCADE;

CREATE TABLE tag
(
  id serial,
  name character varying(255) NOT NULL,
  count integer DEFAULT 1,
  PRIMARY KEY (id),
  CONSTRAINT tag_name UNIQUE (name)
);

CREATE TABLE post_tag
(
  post_id integer NOT NULL,
  tag_id integer NOT NULL,
  PRIMARY KEY (post_id, tag_id)
);


// application.log

2012/06/12 18:49:22 [error] [application] actionCreate(); exception 'PDOException' with message 'SQLSTATE[42602]: Invalid name: 7 ERROR:  invalid name syntax' in /var/www/yii-1.1.10.r3566/framework/db/CDbConnection.php:535


// postgresql log

2012-06-12 18:49:22 WEST ERROR:  invalid name syntax
2012-06-12 18:49:22 WEST STATEMENT:  SELECT CURRVAL($1)
2012-06-12 18:49:22 WEST ERROR:  current transaction is aborted, commands ignored until end of transaction block
2012-06-12 18:49:22 WEST STATEMENT:  DEALLOCATE pdo_stmt_0000000f


Thanks for all the help.
0

#30 User is offline   NCS_One 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 35
  • Joined: 24-August 11

Posted 12 June 2012 - 05:12 PM

I I enabled postgresql parameter logging.

2012-06-12 22:40:22 WEST DETAIL: parameters: $1 = 'tag_id_seq'
2012-06-12 22:40:22 WEST LOG: duration: 0.022 ms execute <unnamed>: SELECT CURRVAL($1)
2012-06-12 22:40:22 WEST DETAIL: parameters: $1 = 'tag_id_seq'
2012-06-12 22:40:22 WEST LOG: duration: 0.051 ms statement: DEALLOCATE pdo_stmt_00000014
2012-06-12 22:40:22 WEST LOG: duration: 0.062 ms parse <unnamed>: SELECT CURRVAL($1)
2012-06-12 22:40:22 WEST ERROR: invalid name syntax
2012-06-12 22:40:22 WEST STATEMENT: SELECT CURRVAL($1)
2012-06-12 22:40:22 WEST ERROR: current transaction is aborted, commands ignored until end of transaction block
2012-06-12 22:40:22 WEST STATEMENT: DEALLOCATE pdo_stmt_0000000f
2012-06-12 22:40:22 WEST LOG: duration: 0.040 ms statement: ROLLBACK

0

#31 User is offline   NCS_One 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 35
  • Joined: 24-August 11

Posted 19 June 2012 - 03:04 PM

Ok,

My problem is on ETaggableBehavior->afterSave, on line 373:

  $tagId = $this->getConnection()->getLastInsertID();

0

#32 User is offline   NCS_One 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 35
  • Joined: 24-August 11

Posted 20 June 2012 - 12:27 AM

If I change that line to:

  $tagId = $this->getConnection()->getLastInsertID('tag_id_seq');


it works.

what could be the issue?
0

#33 User is offline   PrplHaz4 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 92
  • Joined: 28-September 09
  • Location:Boston, MA

Posted 30 January 2013 - 10:03 AM

Can anyone recommend an approach to save the user who set a tag and when it was set?

I'm thinking that the best approach is a custom TaggableBehavior class that overrides afterSave() and saves the additional info using a technique similar to $insertValues in this block of code:


// bind tag to it's model
        $builder->createInsertCommand(
       	$this->getTagBindingTableName(),
				array(
					$this->getModelTableFkName() => $this->getOwner()->primaryKey,
					$this->tagBindingTableTagId => $tagId
       	)
     	)->execute();

0

Share this topic:


  • (2 Pages)
  • +
  • 1
  • 2
  • 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