PHP code example of astina / labels-bundle

1. Go to this page and download the library: Download astina/labels-bundle 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/ */

    

astina / labels-bundle example snippets


class AppKernel extends Kernel {
    public function registerBundles() {
        $bundles = array(
            ...
            new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle(),
            new Astina\Bundle\LabelsBundle\AstinaLabelsBundle(),
            ...
        );
    }
}

class Foo
{
    // ...

    /**
     * @ORM\ManyToMany(targetEntity="Astina\Bundle\LabelsBundle\Entity\Label")
     */
    private $labels;
}

    $builder
        ->add('labels', 'astina_labels', array(
            'categories' => array('category1', 'category2'...),
            'label' => 'Labels',
            '

    public function load(ObjectManager $manager)
    {
        $labelCategory = new LabelCategory();
        $labelCategory->setName('category1');
        $manager->persist($labelCategory);

        foreach ($labelsArray as $labelName) {
            $label = new Label();
            $label->setName($labelName);
            $label->setCategory($labelCategory);
            $manager->persist($label);
        }
        $manager->flush();
    }

$search = $container->get('app.filter_search.foo');
$results = $search->search(new SearchQuery($labels));