Download the PHP package justinvoelker/yii2-tagging without Composer
On this page you can find all versions of the php package justinvoelker/yii2-tagging. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download justinvoelker/yii2-tagging
More information about justinvoelker/yii2-tagging
Files in justinvoelker/yii2-tagging
Package yii2-tagging
Short Description Turn delimited data into tags
License BSD-3-Clause
Informations about the package yii2-tagging
Tagging for Yii2
Turn delimited data into tags
There are multiple extensions for brining tagging functionality into Yii but Tagging aims to be the simplest. Built for Yii2, Tagging does not use additional tables, models, or relationships to store or manage tags or how often they appear. Instead, it works with an existing field of your choosing and turns its contents into tags.
We'll use the following posts
table as an example.
id | post_title | post_body | tags |
---|---|---|---|
1 | My first post! | body of new blog | welcome |
2 | Why Tagging is great | some more content | yii2-tagging,tutorial |
3 | Advanced Tagging tips | most recent post | yii2-tagging,tutorial,advanced |
Tagging includes two classes: TaggingQuery and TaggingWidget. TaggingQuery returns a php array which can be used in form's select field or as input to TaggingWidget which can display the tags as a list or tag cloud.
Keep in mind that your tags don't need to be comma-delimited. You can use practically any delimiter you like!
Installation
Install the extension
The preferred way to install this extension is through composer.
Either run
or add
to the require section of your composer.json
file.
Styles
Follow one of the directions below to use the styles necessary for the tag_cloud
Option 1: Manually combine stylesheets
Open your the vendors\justinvoelker\yii2-tagging\css
directory and add the styles found in tagging.css
to your own stylesheet.
Option 2: Include the delivered asset bundle
Add justinvoelker\tagging\TaggingAsset
as a dependency in your assets\AppAsset
file. It should look similar to the following:
Usage
TaggingQuery
To create a php array of key=>value pairs (where key is the tag and value is the frequency of that tag), use TaggingQuery:
TaggingWidget
To create a tag cloud or list, use TaggingWidget:
TaggingQuery and TaggingWidget
If necessary, you can combine the two. If you have multiple widgets on the same page that will use roughly the same set of data, simple pass the results of an initial TaggingQuery into another TaggingQuery for further limiting or ordering as follows:
The above example will only use one database query but will display two TaggingWidgets. The first will be a tag cloud of tags sorted by name whereas the second will be an unordered list (ul) sorted from most to least frequent.
Available Options
Many options are available for selecting and formatting the data and results. The following examples show which options are available. Exploring the code will give further descriptions of each option.
TaggingQuery
Only select
and from
or an array of items
are required. If all three are specified, the items
values will be used. Note that exclude
and includeOnly
would likely not be used at the same time which is why includeOnly
is commented out in the examples below. Also commented out for this example is items
.
Since TaggingQuery extends yii\db\Query
you can use any other properties available to that class as well. While using where
may come in handy, be careful not to use properties such as distinct
which could have unintended consequences.
The following TaggingQuery would result in an array of the 50 most frequent comma-separated tags from the post table, except for the 'junk' tag, displayed alphabetically.
TaggingWidget
Only items
is required.
All of the selecting, limiting, sorting, and excluding/including of tags is performed by TaggingQuery. Once a list of items is returned from TaggingQuery, it may be passed into a TaggingWidget for display.
Continuing with the previous example, the following TaggingWidget would result in the previously selected tags being displayed in a tag cloud whose text will be justified, with tags ranging in size from 14-22px, and linking to pages in the format of /index.php?r=post/index&tag=TAGNAME