riddlemd / tagit
Lightweight Tag behavior plugin for CakePHP3. Don't fret it, Tagit.
Requires
- php: >=5.5.9
- cakephp/cakephp: >=3.3.2 <4.0.0
Requires (Dev)
This package is not auto-updated.
Last update: 2017-06-28 11:33:11 UTC
README
Installation
You can install this plugin into your CakePHP application using composer.
The recommended way to install composer packages is:
composer require "riddlemd/tagit:1.*"
Configuration
Run this SQL on your database to setup the necessary tables
#!mysql
CREATE TABLE `tagit_tags` (
`id` int(10) UNSIGNED NOT NULL,
`name` varchar(255) NOT NULL,
`count` int(10) UNSIGNED NOT NULL DEFAULT '0',
`created` datetime DEFAULT NULL,
`modified` datetime DEFAULT NULL
);
CREATE TABLE `tagit_tag_associations` (
`id` int(10) UNSIGNED NOT NULL,
`tag_id` int(10) UNSIGNED NOT NULL,
`fk_id` int(10) UNSIGNED NOT NULL,
`fk_table` varchar(255) NOT NULL,
`created` datetime DEFAULT NULL,
`modified` datetime DEFAULT NULL
);
How to use
Install via composer
Add
$this->addBehavior('Riddlemd/Tagit.Tagit');
to table's initialize method you want to enable Tagit on.To create tags write to the
tags_string
property of entities retrieved from table from step 2. (Example$entity->tags_string = 'Tag1, Tag2,Tag3, Tag 4';
)To read tags call the formatResults method of your query before accessing it and give it
$this->TABLE_NAME->behaviors()->get("Tagit")->getResultsFormatter()
, where TABLE_NAME is name of the table you are using. (Example$articles = $this->Articles->find()->formatResults($this->Articles->behaviors()->get("Tagit")->getResultsFormatter());
) You can assign a variable with$this->TABLE_NAME->behaviors()->get("Tagit")->getResultsFormatter()
to use on a single entities as well if you are using$this->Articles->get()
or simular (Example:$resultsFormatter = $this->Articles->behaviors()->get("Tagit")->getResultsFormatter(); $article = $resultsFormatter($this->Articles->get(1));
)
The plugin has several configuration options that can be modified via the addBehavior call, reference the Riddlemd/Tagit/src/Model/Behavior/TagitBehavior.php $_defaultConfig for a list of them.
There are also a few config options in the config/plug.php which you can override in your config/app.php, do not edit the plugin.php as it will be overwritten on upgrades.