icap-lyon1/simple-tag-bundle
Composer 安装命令:
composer require icap-lyon1/simple-tag-bundle
包简介
Symfony TagBundle that easily adds tags to any entity
关键字:
README 文档
README
Symfony2 bundle to easily manage tags with any entity.
Installation
To install this bundle please follow the next steps:
First add the dependency in your composer.json file:
"require": { ... "icap-lyon1/simple-tag-bundle": "2.0.*" },
Then install the bundle with the command:
php composer update
Enable the bundle in your application kernel:
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new ICAPLyon1\Bundle\SimpleTagBundle\ICAPLyon1SimpleTagBundle(), ); }
Then update your database schema:
php app/console doctrine:schema:update --force
Then install the bundle assets:
php app/console assets:install
// if you want to create a symlink:
php app/console assets:install --symlink
Finally include the bundle configuration file in your app configuration file:
// app/config/config.yml imports: // ... - { resource: @ICAPLyon1SimpleTagBundle/Resources/config/config.yml }
Now the Bundle is installed.
How to use
In order to add tags to an entity, the entity has to implements TaggableInterface example:
<?php // Acme/Bundle/AcmeBundle/Entity/TaggableEntity.php namespace Acme\Bundle\AcmeBundle\Entity; use ICAPLyon1\Bundle\SimpleTagBundle\Entity\TaggableInterface; class TaggableEntity implements TaggableInterface { // Your code here }
Then when you wish to associate an entity with a tag, simply call the icaplyon1_simpletag.manager service to create a form and process it as explained below:
// Instead of standard form creation // $form = $this->createForm(new MyObjectType(), $myObject); // Do this: $form = $this->get('icaplyon1_simpletag.manager')->createForm( new TaggableEntityType(), $entity);
To save and associate the tags with your entity, call the processForm function like this:
if ($form->isValid()) { $myObject = $this->get('icaplyon1_simpletag.manager')->processForm($form); return $this->redirect($this->generateUrl(...)); }
The processForm($form) method will retrieve the input tags, add new (not already associated) tags and remove associated tags that are not included in the input list
#Functions of icaplyon1_simpletag.manager
Associate tags
if you want to associate a tag with your entity:
// ... //Associate tags with your entity $this->get("icaplyon1_simpletag.manager")->addTag($tag, $entity); // ...
if you want to associate multiple tags with your entity:
// ... //Associate tags with your entity $this->get("icaplyon1_simpletag.manager")->addTags($tags, $entity); // ...
Dissociate tags
if you want to dissociate a tag from your entity:
$this->get("icaplyon1_simpletag.manager")->removeTag($tag, $entity);
if you want to dissociate multiple tags from your entity:
$this->get("icaplyon1_simpletag.manager")->removeTags($tags, $entity);
Remove all tags from an entity
if you want to remove all tags from your entity (DO THIS WHEN YOU ARE DELETING YOUR ENTITY IN ORDER TO AVOID KEEPING RUBBISH IN YOUR DATABASE):
$this->get("icaplyon1_simpletag.manager")->removeAllTags($entity);
example in method:
// ... public function deleteAction(Request $request, $id) { $form = $this->createDeleteForm($id); $form->bind($request); if ($form->isValid()) { $em = $this->getDoctrine()->getManager(); $entity = $em->getRepository('ICAPLyon1TestTagBundle:TaggableEntity')->find($id); if (!$entity) { throw $this->createNotFoundException('Unable to find TaggableEntity entity.'); } //Remove all tags for entity $this->get("icaplyon1_simpletag.manager")->removeAllTags($entity); //Remove entity from database $em->remove($entity); $em->flush(); } return $this->redirect($this->generateUrl('taggableentity')); } // ...
Get tags
In your manager (php)
To get all tags for your entity:
$this->get("icaplyon1_simpletag.manager")->getTags($entity);
In a twig template
To get the tags associated to an object a twig extension has been created, use it as follows:
{{ entity_tags(entity) }}
Get all stored tags
You can get all stored tags to use them for example for autocomplete
Using php
$this->get("icaplyon1_simpletag.manager")->getAllTags();
Using twig
{{ all_tags() }}
icap-lyon1/simple-tag-bundle 适用场景与选型建议
icap-lyon1/simple-tag-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 634 次下载、GitHub Stars 达 1, 最近一次更新时间为 2013 年 02 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「tag」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 icap-lyon1/simple-tag-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 icap-lyon1/simple-tag-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 icap-lyon1/simple-tag-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The tag extension for the yii framework
Provides support for tag aware cache for Yii1 application
Sistema AMOS per le TAG
Easily integrates Google Tag Manager code with your Neos website.
phlexible suggest bundle
Simple class for generating HTML tag.
统计信息
- 总下载量: 634
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 18
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0
- 更新时间: 2013-02-25