PHP code example of pedro-teixeira / grid-bundle
1. Go to this page and download the library: Download pedro-teixeira/grid-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/ */
pedro-teixeira / grid-bundle example snippets
// application/ApplicationKernel.php
public function registerBundles()
{
$bundles = array(
new PedroTeixeira\Bundle\GridBundle\PedroTeixeiraGridBundle()
);
}
namespace PedroTeixeira\Bundle\TestBundle\Grid;
use PedroTeixeira\Bundle\GridBundle\Grid\GridAbstract;
/**
* Test Grid
*/
class TestGrid extends GridAbstract
{
/**
* {@inheritdoc}
*/
public function setupGrid()
{
$this->addColumn('Hidden Field')
->setField('hidden')
->setIndex('r.hidden')
->setExportOnly(true);
$this->addColumn('ID')
->setField('id')
->setIndex('r.id')
->getFilter()
->getOperator()
->setComparisonType('equal');
$this->addColumn('Created At')
->setField('createdAt')
->setIndex('r.createdAt')
->setFilterType('date_range')
->setRenderType('date');
$this->addColumn('Name')
->setField('name')
->setIndex('r.name');
$this->addColumn('Number')
->setField('number')
->setIndex('r.number')
->setFilterType('number_range');
$this->addColumn('Options')
->setField('option')
->setIndex('r.options')
->setFilterType('select')
->getFilter()
->setOptions(array(
'key' => 'value'
));
$this->addColumn('Action')
->setTwig('PedroTeixeiraTestBundle:Test:gridAction.html.twig')
->setFilterType(false);
}
}
namespace PedroTeixeira\Bundle\TestBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use JMS\SecurityExtraBundle\Annotation\Secure;
/**
* Default controller
*/
class DefaultController extends Controller
{
/**
* @Route("/", name="test")
* @Template()
*
* @return array
*/
public function indexAction()
{
/** @var \Doctrine\ORM\EntityRepository $repository */
$repository = $this->getDoctrine()->getRepository('PedroTeixeiraTestBundle:TestEntity');
$queryBuilder = $repository->createQueryBuilder('r');
/** @var \PedroTeixeira\Bundle\TestBundle\Grid\TestGrid $grid */
$grid = $this->get('pedroteixeira.grid')->createGrid('\PedroTeixeira\Bundle\TestBundle\Grid\TestGrid');
$grid->setQueryBuilder($queryBuilder);
if ($grid->isResponseAnswer()) {
return $grid->render();
}
return array(
'grid' => $grid->render()
);
}
}