Released QuickTag - A Tag Library for Silex

  • Tags: php, projects,
  • Written on: December 28, 2012

I wrote this component to provide a composer available tag library that uses doctrine DBAL as its back-end. It can be downloaded from github.

A Tag has the following properties:

  • Title (45 character) name. no default case upper or lower fine.
  • Weight (float) used to order a set of tags.
  • Created (DateTime) used to sort old and new tags
  • UserContext (integer) restrict tags to a given user id.

Features of the library:

  • Written using Doctrine DBAL.
  • Optional Restful Silex API Supports GET/POST/PUT/DELETE.
  • Can be used with Zend/Tag/Cloud, doing tag clouds is easy.
  • PHP 5.3 and up.

API Methods

Store a tag Create/Update

    use DateTime;
    use QuickTag\Model\StoredTag;
    $storedTag = new StoredTag();
    $storedTag->setTagCreated(new DateTime());
    # fetch service from the provider
    $result = $tagService->storeTag($storeTag);
    if($result) {
        echo 'tag has been stored at id '. $storedTag->getTagId();

During an update the id must be set and only the title and weight and user context can be changed.

Lookup a tag by id.


    use QuickTag\Model\StoredTag;
    # fetch service from the provider
    $storeTag = $tagService->lookupTag($id);
    if($storedTag instanceOf StoredTag ) {
        echo 'tag has been gound at id '. $storedTag->getTagId();

Searching for a tag

    # Search for tags started with titte `my` and belong to user 3
    $tagCollection = $tagService->findTag()
    if(count($tagCollection) > 0 ) {
        echo sprintf('found %s number of tags',count($tagCollection));

Removing a Tag.

    use QuickTag\Model\StoredTag;
    $id = 1;
    # fetch service from the provider
    $storeTag = $tagService->lookupTag($id);
    $result = $tagService->removeTag($storeTag);
    if($result) {
        echo 'tag has been removed at id '. $storedTag->getTagId();

The API under QuickTag\Silex\Provider\TagServiceProvider has basic examples on how to use the library.

Using Zend Tag Cloud

    use Zend\Tag\Cloud;
    use QuickTag\Model\StoredTag;
    $tagA = new StoredTag();
    $tagB = new StoredTag();
    $tagC = new StoredTag();
    $cloud = new Cloud(array(
        'tags' => array(
    // Render the cloud
    echo $cloud;