Taggable Behaviour This extension allows active record model to manage tags.
#21
Posted 04 March 2011 - 05:01 AM
Enjoying Yii? Star us at github
Support me so I can work more on Yii: https://www.patreon.com/samdark
#22
Posted 04 March 2011 - 05:08 AM
samdark, on 04 March 2011 - 05:01 AM, said:
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, ), ) ); }
#23
Posted 04 March 2011 - 05:13 AM
Enjoying Yii? Star us at github
Support me so I can work more on Yii: https://www.patreon.com/samdark
#25
Posted 10 August 2011 - 01:58 AM
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' ), ) ); }
#26
Posted 07 April 2012 - 04:08 PM
#27
Posted 23 April 2012 - 04:55 AM
Enjoying Yii? Star us at github
Support me so I can work more on Yii: https://www.patreon.com/samdark
#28
Posted 23 April 2012 - 05:33 AM

#29
Posted 12 June 2012 - 01:04 PM
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.
#30
Posted 12 June 2012 - 05:12 PM
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
#31
Posted 19 June 2012 - 03:04 PM
My problem is on ETaggableBehavior->afterSave, on line 373:
$tagId = $this->getConnection()->getLastInsertID();
#32
Posted 20 June 2012 - 12:27 AM
$tagId = $this->getConnection()->getLastInsertID('tag_id_seq');
it works.
what could be the issue?
#33
Posted 30 January 2013 - 10:03 AM
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();
#34
Posted 26 September 2013 - 03:34 PM
#35
Posted 26 September 2013 - 08:21 PM
$post->setTags('tag1, tag2, tag3'); $post->save();
#36
Posted 30 September 2013 - 11:12 AM
PrplHaz4, on 26 September 2013 - 08:21 PM, said:
$post->setTags('tag1, tag2, tag3'); $post->save();
Ok, I want to use tags on a "Restaurant" Module. I put the behavior into Tag.ph. This is what i have on behavior:
function behaviors() { return array( 'tags' => array( 'class'=>'ext.taggable.EARTaggableBehavior', 'tagTable'=>'tag', 'tagModel'=>'Tag', 'tagBindingTable'=>'post_tag', 'modelTableFk'=>'post_id', 'tagTablePk'=>'id', 'tagTableName'=>'name', 'tagTableCount'=>'count', 'tagBindingTableTagId'=>'tag_id', ) ); }
I have a field named "tag" on my Restaurant _form because here is where I want to put the tags that will save.
<div class="row" > <?php echo $form->labelEx($model, 'tag'); ?> <?php echo $form->textArea($model,'tag'); ?> <?php echo $form->error($model, 'tag'); ?> </div>
On create function on RestaurantsController I have the next lines for extracting the tags from the field and trying to save them
$taag = $_POST['Restaurants']['tag']; $tagg =array(); $tagg = explode(" ", $taag); $post = new Tag(); foreach ($tagg as $t) { $post->setTags($tagg); $post->save(); }
But now is sending me this error Property "Tag.title" is not defined.
Am I doing something wrong. Is not the correct way I'm doing it? Thanks in advice.
#37
Posted 30 September 2013 - 11:15 PM
Arely, on 30 September 2013 - 11:12 AM, said:
Sorry, not much time to really go over this, but I see something immediately - the tag behavior should be going in your Restaurant model - since that is the model that will be using the tags. I'm guessing it is Restaurant.php
#38
Posted 10 March 2014 - 07:09 AM
$this->widget('zii.widgets.grid.CGridView', array( 'id' => 'disks-grid', 'dataProvider' => $model->search(), 'filter' => $model, 'columns' => array( // additional column definitions array( 'name' => 'tags_with_model', 'header' => 'Tags', 'type' => 'raw', 'filter' => FALSE, 'value' => $model->tags_with_model->toString(), ),
Unfortunately, that produces nothing. No errors, just a totally blank column. (Interestingly, I was able to use <?php echo $model->tags_with_model->toString(); ?> to display the tags in view.php, and it worked quite nicely.) Apparently, something happens in CGridView to prevent toString() from working.
By the way, my behavior in the model looks like:
return array( 'tags_with_model' => array( 'class' => 'ext.yiiext.behaviors.model.taggable.EARTaggableBehavior', 'tagTable' => 'video_tags', 'tagModel' => 'VideoTags', 'tagBindingTable' => 'video_disks_tags', 'modelTableFk' => 'disksId', 'tagTablePk' => 'id', 'tagTableName' => 'name', 'tagTableCount' => 'frequency', 'tagBindingTableTagId' => 'tagId', 'cacheID' => 'cache', 'createTagsAutomatically' => TRUE, ) ); }
I've also tried a virtual attribute like this:
public function getVideoTags() { return $this->tags_with_model->toString(); }
I added that to the CActiveDataProvider attributes in search() in the model and to CGridView, but I still get an empty column.
Can anyone tell me how to get a column in CGridView that displays the tags for each model?