1. Go to this page and download the library: Download matycz/lemo-grid 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/ */
matycz / lemo-grid example snippets
'LemoGrid',
namespace Foo;
use LemoGrid\ModuleManager\Feature\GridProviderInterface;
use Laminas\ModuleManager\Feature\ControllerProviderInterface;
use Laminas\ModuleManager\Feature\ServiceProviderInterface;
class Module implements
ControllerProviderInterface,
GridProviderInterface,
ServiceProviderInterface
{
...
/**
* @inheritdoc
*/
public function getControllerConfig()
{
return array(
'factories' => array(
'Foo\Controller\Bar' => function($controllerManager) {
$controller = new Controller\BarController();
$controller->setGridBar($controllerManager->getServiceLocator()->get('Foo\Grid\Bar'));
$controller->setServiceBar($controllerManager->getServiceLocator()->get('Foo\Service\Bar'));
return $controller;
},
)
);
}
/**
* @inheritdoc
*/
public function getGridConfig()
{
return array(
'factories' => array(
'Foo\Grid\Bar' => function () {
$grid = new Grid\Bar();
return $grid;
},
)
);
}
/**
* @inheritdoc
*/
public function getServiceConfig()
{
return array(
'factories' => array(
'Foo\Service\Bar' => function ($serviceManager) {
$service = new Service\Bar($serviceManager);
$service->setEntityManager($serviceManager->get('Doctrine\ORM\EntityManager'));
return $service;
},
),
);
}
...
}
namespace Foo\Controller;
use Foo\Grid\Bar as GridBar;
use Foo\Service\Bar as ServiceBar;
use Laminas\Mvc\Controller\AbstractActionController;
use Laminas\View\Model\ViewModel;
class BarController extends AbstractActionController
{
/**
* @var GridBar
*/
protected $gridBar;
/**
* @var ServiceBar
*/
protected $serviceBar;
/**
* Page with grid example
*
* @return ViewModel
*/
public function indexAction()
{
$adapter = new \LemoGrid\Adapter\Doctrine\QueryBuilder();
$adapter->setQueryBuilder($this->getServiceBar()->getQueryBuilderInstanceForGrid());
$platform = new \LemoGrid\Platform\JqGrid();
$grid = $this->getGridBar();
$grid->setAdapter($adapter);
$grid->setPlatform($platform);
$grid->setParams($this->params()->fromQuery());
return new ViewModel(array(
'grid' => $grid
));
}
...
/**
* @param GridBar $gridBar
* @return BarController
*/
public function setGridBar(GridBar $gridBar)
{
$this->gridBar = $gridBar;
return $this;
}
/**
* @return GridBar
*/
public function getGridBar()
{
return $this->gridBar;
}
/**
* @param ServiceBar $serviceBar
* @return BarController
*/
public function setServiceBar(ServiceBar $serviceBar)
{
$this->serviceBar = $serviceBar;
return $this;
}
/**
* @return ServiceBar
*/
public function getServiceBar()
{
return $this->serviceBar;
}
}
namespace Foo\Service;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\QueryBuilder;
class Bar
{
/**
* @var EntityManager
*/
protected $entityManager;
/**
* Return instance of QueryBuilder for grid
*
* @return QueryBuilder
*/
public function queryGrid()
{
$qb = $this->getEntityManager()->createQueryBuilder()
->select(array('rootAlias'))
->from('Foo\Entity\Bar', 'rootAlias');
return $qb;
}
/**
* Set entity manager
*
* @param EntityManager $entityManager
* @return Bar;
*/
public function setEntityManager(EntityManager $entityManager)
{
$this->entityManager = $entityManager;
return $this;
}
/**
* Get entity manager
*
* @return EntityManager
*/
public function getEntityManager()
{
return $this->entityManager;
}
}