PHP code example of ekyna / table-bundle

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

    

ekyna / table-bundle example snippets


    // app/AppKernel.php
    public function registerBundles()
    {
        $bundles = array(
            // other bundles ...
            new Ekyna\Bundle\TableBundle\EkynaTableBundle(),
        );
     
        return $bundles;
    }

    // src/Acme/DemoBundle/Table/Type/BrandType.php
    namespace Acme\DemoBundle\Table\Type;
    
    use Ekyna\Component\Table\AbstractTableType;
    use Ekyna\Component\Table\TableBuilderInterface;
    use Symfony\Component\OptionsResolver\OptionsResolverInterface;
    
    class BrandType extends AbstractTableType
    {
        public function buildTable(TableBuilderInterface $tableBuilder)
        {
            $tableBuilder
                ->addColumn('id', 'number', array(
                    'sortable' => true,
                ))
                ->addColumn('title', 'text', array(
                    'label' => 'Title',
                    'sortable' => true,
                ))
                ->addFilter('id', 'number')
                ->addFilter('title', 'text', array(
                    'label' => 'Title'
                ))
            ;
        }
        
        public function setDefaultOptions(OptionsResolverInterface $resolver)
        {
            parent::setDefaultOptions($resolver);
        
            $resolver->setDefaults(array(
                'data_class' => 'Acme\DemoBundle\Entity\Brand',
            ));
        }
        
        public function getName()
        {
            return 'acme_demo_brand';
        }
    }

    // src/Acme/DemoBundle/Controller/BrandController.php
    namespace Acme\Demo\Controller;
    
    use Symfony\Bundle\FrameworkBundle\Controller\Controller;
    use Symfony\Component\HttpFoundation\Request;
    // use Acme\DemoBundle\Table\Type\BrandType;
    
    class ResourceController extends Controller
    {
        public function indexAction(Request $request)
        {
            $table = $this->get('table.factory')
                /*->createBuilder(new BrandType(), array( // instance
                    'name' => 'my_brand_list,
                ))*/
                ->createBuilder('acme_demo_brand', array( // service
                    'name' => 'my_brand_list',
                ))
                ->getTable($request)
            ;
            
            return $this->render('AcmeDemoBundle:Brand:index.html.twig', array(
                'brands' => $table->createView(),
            ));
        }
    }