PHP code example of kit-tools / yii2-tags

1. Go to this page and download the library: Download kit-tools/yii2-tags library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kit-tools / yii2-tags example snippets


'controllerMap' => [
    'tag' => 'kittools\tags\controllers\TagController'
],


...
/**
 * @var array list of tags entered by the user.
 */
public $tagList = [];
...


public function rules(){
    ...
    ['tagList', ' => 'Tags are filled incorrectly.'],
    ...
}

    ['tagList', '

public function behaviors()
{
    return [
        ...
        'tagBehavior' => [
            'class' => TagBehavior::className(),
        ],
        ...
    ];
}

$model->detachBehavior('tagBehavior');


use kittools\tags\models\Tag;
use kittools\tags\models\TagEntityRelation;
...
public function getTags()
{
    return $this->hasMany(Tag::class, ['id' => 'tag_id'])
        ->viaTable(TagEntityRelation::tableName(), ['entity_id' => 'id'], function($query){
            $query->andWhere([TagEntityRelation::tableName() . '.entity' => static::class]);
        });
}


use kittools\tags\widgets\TagInputWidget;
...


use kittools\tags\widgets\TagInputWidget;
use yii\helpers\ArrayHelper;
use kittools\tags\models\Tag;
...


use kittools\tags\widgets\TagsEntityWidget;
...
echo TagsEntityWidget::widget([
    'model' => $model,
    'caseRegister' => 'upper',
    'tagUrl' => ['site/tag'],
    'delimiter' => ', ',
 ]);
...



use kittools\tags\widgets\CloudTagsWidget;
use app\models\News;
...
echo CloudTagsWidget::widget([
    'entity' => News::className(),
    'type' => CloudTagsWidget::TYPE_WEIGHT,
    'shuffleTags' => false,
    'tagUrl' => ['/news/tag'],
    'coefficientIncreaseFont' => 1,
    'tagPrefix' => '',
    'tagUrlOptions' => ['style' => 'color: #003366;', 'target' => '_blank']
]);
...