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: -----

#1 User is offline   samdark 

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

Posted 08 December 2009 - 10:10 AM

This extension allows active record model to manage tags.

Feel free to request new features, ask questions and report bugs.

http://www.yiiframew...nsion/taggable/
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#2 User is offline   Raoul 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 636
  • Joined: 29-November 08
  • Location:Paris, France

Posted 13 December 2009 - 06:47 AM

hi,
where can it be downloaded ? The extension page doesn't provide any file !

8)
0

#3 User is offline   samdark 

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

Posted 13 December 2009 - 01:22 PM

There is a link to SVN repository. You can check files out of it.
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#4 User is offline   Raoul 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 636
  • Joined: 29-November 08
  • Location:Paris, France

Posted 13 December 2009 - 04:52 PM

ok, thanks samdark
B)
0

#5 User is offline   samdark 

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

Posted 27 December 2009 - 05:26 PM

Updated extension. This version is not backwards compatible to 0.6.

Changelog:

[*] Do not try to delete tag bindings when inserting new record.
[+] Added taggedWith() alias withTags().
[-] Removed getCountByTags(), findAllByTags(). Use taggedWith().
[+] Method chaining: $post->addTags("yii, php")->save();
[+] New syntax: $posts = Post::model()->taggedWith(array('php', 'yii'))->findAll();
[*] Added parent:: calls in event handlers.
[+] Added hasTags() and it's alias hasTag() to check if all tags specified are attached to current model.
[+] New syntax: echo $post->tags (or by what name behaviour is attached) will print comma separated tags.
[*] getTags now returns array since implode is really easy to do yourself.
[-] Removed getTagsArray().
[*] addTags(), removeTags(), setTags() are now accept both string and array.
[+] Added addTag() as alias of addTags(), removeTag() as alias of removeTags().
[*] Some methods are now protected.
[*] Added $with to findAllByTags().
[+] getAllTags().
[+] Unit tests.
[+] createTagsAutomatically option allows to throw exception when adding nonexisting tag.
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#6 User is offline   bram 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 28-December 09

Posted 28 December 2009 - 08:03 AM

hi

since i just started using yii I might be missing something
but it seems that the init method is never called
which means the cache will not be initialized

i use the behaviour like this in my project controller:

public function behaviors()
{
	return array(
		'TaggableBehaviour' => array(
			'class' => 'ext.CTaggableBehaviour.CTaggableBehaviour',
			'tagBindingTable' => 'project_tag',
			'cacheID' => 'cache',
		)
	);
}


is this a bug?

thanks
bram
0

#7 User is offline   samdark 

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

Posted 28 December 2009 - 10:42 AM

Yes, it was. Just fixed it in SVN. Thanks.

Another changes are:
- Now you can set tagId field name for binding table.
- Added "Using multiple tag groups" to readme.
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#8 User is offline   bram 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 28-December 09

Posted 29 December 2009 - 11:33 AM

thanks!
0

#9 User is offline   bram 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 28-December 09

Posted 30 December 2009 - 08:36 AM

i found another cache issue

getAllTags
getAllTagsWithModelsCount

both store the result in the cache but the value is never changed when a tag is added / removed
i think it might be useful to trigger an event when tags are updated
that way it would be easier to extend the class and make use of the caching

it would also be nice to use the cached tags to check if there is something to update in afterSave

just some thoughts..
1

#10 User is offline   samdark 

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

Posted 11 January 2010 - 07:30 PM

Released 0.9:
- Added resetAllTagsCache() and resetAllTagsWithModelsCountCache().
- Fixed getAllTags() and getAllTagsWithModelsCount() cache issues.
- Now tags are saved on save() only if they were changed.
- Extension is now compatible only with Yii 1.1.
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#11 User is offline   samdark 

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

Posted 22 February 2010 - 03:54 PM

Released 1.0

1.0
[*] More PHPDoc documentation.
[*] Fixed possible cache keys overlap when using multiple tag sets with one model.
[+] Nice HTML rendered documentation included.
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#12 User is offline   augustin 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 07-April 10

Posted 14 May 2010 - 04:01 AM

how should i use this extension in such a case:

I have a model. The model uses etaggable behaviour. I search the model instances and want to show results (model instances and theirs tags). If I add getTags() in afterFind() method, there will be a query to DB for each instance, which is not what I want. How should it be done?
0

#13 User is offline   samdark 

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

Posted 14 May 2010 - 04:49 AM

What about using cache?
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#14 User is offline   augustin 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 07-April 10

Posted 15 May 2010 - 04:34 AM

View Postsamdark, on 14 May 2010 - 04:49 AM, said:

What about using cache?


I don't understand this 'cache suggestion', because I can have a plenty of models and plenty of queries.

I'm rather looking for 'eager loading' -- I want my model instances WITH theirs tag (more sql columns in one query). Of course I could do it not using 'taggable behaviour', but if I already use your extension it would be nice to use it consistently.

regards,
augustin
0

#15 User is offline   samdark 

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

Posted 16 May 2010 - 05:46 AM

Right now I'm busy with Yii core. Will try adding it later: http://code.google.c...es/detail?id=24
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#16 User is offline   samdark 

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

Posted 11 June 2010 - 07:23 AM

Released 1.3.
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#17 User is offline   Nayjest 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 85
  • Joined: 05-June 10
  • Location:Ukraine, Kiev

Posted 11 June 2010 - 07:47 AM

Eng:
How to organize views for create/update actions with taggable model?
Validation?
If i use code example below, tags field clears after validation fail of other fields.
Ru:
Очень не хватает примера, как правильно реализовать представление для создания/обновления модели с Taggable Behaviour и валидацию. Дело в том, что во первых в MyModel.rules() правила валидации тегов засунуть не получается, а во вторых: если в представление для создания/обновления модели просто засунуть еще одно поле (например так)
in _form.php:
<div class="row">
        <?php echo $form->labelEx($model,'tags'); ?>
        <?php echo $form->textField($model,'tags'); ?>
        <?php echo $form->error($model,'tags'); ?>
</div>

in model:
protected function beforeSave()
    {
        if(parent::beforeSave())
        {
           
            $this->addTags($_POST['Text']['tags']);
            return true;
        }
        else
            return false;
    }

То при неудачной валидации поле с заполненными тегами обновляется.
Web-superman. My blog about web development (russian).
0

#18 User is offline   samdark 

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

Posted 11 June 2010 - 08:12 AM

Nayjest
You can use toString() to fill tags for a model.
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#19 User is offline   Nayjest 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 85
  • Joined: 05-June 10
  • Location:Ukraine, Kiev

Posted 11 June 2010 - 10:09 AM

samdark, можно детальнее? Я это реализовал, как показано в коде выше и оно работает, теги сохраняются, но я не уверен, что это лучший путь + я не знаю, как архитектурно правильно реализовать валидацию.
Еще поле с тегами обнуляется после неудачной валидации формы, если что-нибудь другое заполнить неправильно (модель, контроллеры и представления стандартные для CRUD, сгенерированы с помощью инструментов yii).
Вручную делать преобразование массива тегов в строку для этого мне вроде-бы нигде не нужно было.
Web-superman. My blog about web development (russian).
0

#20 User is offline   psikocrisis 

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

Posted 04 March 2011 - 04:30 AM

Hi,

I'm using the following code
$model->tags->toString();


but I get

Fatal error: Call to a member function toString() on a non-object

:mellow:
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