riddlemd/tagit

This package is abandoned and no longer maintained. No replacement package was suggested.

Lightweight Tag behavior plugin for CakePHP3. Don't fret it, Tagit.

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Type:cakephp-plugin

dev-master 2017-06-20 20:09 UTC

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

  1. Install via composer

  2. Add $this->addBehavior('Riddlemd/Tagit.Tagit'); to table's initialize method you want to enable Tagit on.

  3. 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';)

  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.