-
Notifications
You must be signed in to change notification settings - Fork 7
2. Basic setup
kalt edited this page Sep 13, 2010
·
9 revisions
Let’s see how to tag any Model. The plugin provides a Behavior and a Helper to achieve that.
class Article extends AppModel
{
var $actsAs = array('Tagging.Taggable');
}
class ArticlesController extends AppController
{
var $helpers = array('Tagging.Tagging');
}
A single input field for comma-separated tags, in add/edit views.
echo $form->input('tags');
echo $tagging->input('tags');
Requires jQuery in <head>...</head>
That’s it, you can tag any Model.
If you choose this solution to add tags to a record, you will see suggested tags as you type.
You can change any option as with the core Paginator Helper:
$tagging->options(array('option_key' => 'value', ...));
Here are the default options :
- selector : DOM selector to be observed (try to keep it simple, one id (‘#xyz’) or one class (‘.xyz’) only). Defaults to ‘.tagSuggest’.
- url : url to get suggestions via ajax POST call (JSON formatted response). Defaults to ‘/tagging/tags/suggest’.
- delay : sets the delay between keyup and the request (in milliseconds). Defaults to 500.
- matchClass : CSS class applied to the suggestions. Defaults to ‘tagMatches’.
- sort : boolean to force the sorted order of suggestions. Defaults to false.
- tagContainer : the type of element used to contain the suggestions. Defaults to ‘span’.
- tagWrap : the type of element the suggestions a wrapped in. Defaults to ‘span’.
- tags : array of tags specific to this instance of element matches (if you don’t want to use ajax but a predefined list of tags). Defaults to null.
If you want to change the way tag suggestions are displayed, simply change the ‘matchClass’ option and provide your own CSS styles according to the new ‘matchClass’ name.
The second parameter of $tagging→input() can be an array of options just as the classic $form→input().