承接 justinvoelker/yii2-tagging 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

justinvoelker/yii2-tagging

Composer 安装命令:

composer require justinvoelker/yii2-tagging

包简介

Turn delimited data into tags

关键字:

README 文档

README

#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

php composer.phar require --prefer-dist justinvoelker/yii2-tagging "*"

or add

"justinvoelker/yii2-tagging": "*"

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:

...
public $depends = [
    'yii\web\YiiAsset',
    'yii\bootstrap\BootstrapAsset',
    'justinvoelker\tagging\TaggingAsset',
];
...

##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:

$query = new TaggingQuery;
$tags = $query
    ->select('tags')
    ->from('posts')
    ->getTags();

###TaggingWidget

To create a tag cloud or list, use TaggingWidget:

echo TaggingWidget::widget([
    'items' => $tags,
]);

###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:

$query = new TaggingQuery;

$tagsA = $query
    ->select('tags')
    ->from('posts')
    ->displaySort(['name' => SORT_ASC])
    ->getTags();
echo TaggingWidget::widget([
    'items' => $tagsA,
    'format' => 'cloud',

$tagsB = $query
    ->items($tagsA)
    ->displaySort(['freq' => SORT_DESC])
    ->getTags();
echo TaggingWidget::widget([
    'items' => $tagsB,
    'format' => 'list',
]);

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.

$query = new TaggingQuery;
$tags = $query
    // used to refine an existing list
    //->items($existingTaggingQueryResults)
    // field that contains the desired tags
    ->select('tags')
    // table to select from
    ->from('post')
    // delimiter (default: `,` (comma))
    ->delimiter(',')
    // number of tags to display (omit for all tags)
    ->limit(50)
    // order used when a limit is being applied
    ->limitSort(['freq' => SORT_DESC, 'name' => SORT_ASC])
    // order of the resulting list
    ->displaysort(['name' => SORT_ASC])
    // array of tags to be excluded
    ->exclude(['junk'])
    // array of tags to be included (all other omitted)
    //->includeOnly(['feature', 'special'])
    // return the array of tag=>frequency pairs
    ->getTags();

###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

echo TaggingWidget::widget([
    // TaggingQuery results
    'items' => $tags,
    // smallest tag size (default: 14)
    'smallest' => '14',
    // largest tag size (default: 22)
    'largest' => '22',
    // unit for tag sizes (default: px)
    'unit' => 'px',
    // display format of 'cloud', 'ul', or 'ol' (default: cloud)
    'format' => 'cloud',
    // url for links (omit for no link)
    'url' => ['post/index'],
    // parameter to be appended to url with tag
    'urlParam' => 'tag',
    // options applied to the list
    'ulOptions' => ['style' => 'text-align:justify'],
    // options applied to the list item
    'liOptions' => [],
    // options applied to the link (if present)
    'linkOptions' => [],
]);

justinvoelker/yii2-tagging 适用场景与选型建议

justinvoelker/yii2-tagging 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.62k 次下载、GitHub Stars 达 8, 最近一次更新时间为 2015 年 02 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「tag」 「yii2」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 justinvoelker/yii2-tagging 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 justinvoelker/yii2-tagging 我们能提供哪些服务?
定制开发 / 二次开发

基于 justinvoelker/yii2-tagging 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 4.62k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 8
  • 点击次数: 19
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 8
  • Watchers: 4
  • Forks: 6
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2015-02-11