Skip to main content

Zend Expressive

Integrating Zend Form in Zend Expressive and Zend View

Example is based using Aura.Di. But the functionality will be same for any containers. First register the service Zend\View\HelperPluginManager, so that we can access the same object. To register the form helpers, create the object of Zend\Form\View\HelperConfig and pass the Zend\View\HelperPluginManager service. Example code with Aura.Di version 3 configuration. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 <?php use Aura\Di\ContainerConfig; use Aura\Di\Container; use Zend\Form\View\HelperConfig; class ViewHelper extends ContainerConfig { public function define(Container $di) { $di->set('Zend\View\HelperPluginManager', $di->lazyNew('Zend\View\HelperPluginManager')); } public function modify(Container $di) { $serviceManager = $di->get('Zend\View\HelperPluginManager'); $helper = new HelperConfig(); $helper->configureServiceManager($servicemanager); } } Creating your own zend-view helper # Create your helper class 1 2 3 4 5 6 7 8 9 10 11 12 13 <?php namespace App\View\Helper; use Zend\View\Helper\AbstractHelper; class HasError extends AbstractHelper { // add as many parameters you want to pass from the view public function __invoke() { // some code } } Registering your helper class. First get the Zend\View\HelperPluginManager service.

Eloquent and Pagination Inside Zend Expressive

·154 words·1 min
Recently working with eloquent (Laravel’s orm), zend expressive and zend view, I wanted to integrate pagination. It was simple as registering a Paginator middleware. 1 2 3 4 5 6 7 8 9 10 11 12 <?php use Illuminate\Pagination\Paginator; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; IlluminatePaginator::currentPageResolver(function ($pageName) use ($request) { $params = $request->getQueryParams(); return empty($params[$pageName]) ? 1 : $params[$pageName]; }); IlluminatePaginator::currentPathResolver(function () use ($request) { return $request->getUri()->getPath(); }); and you can call paginate on the Model. Eg : Consider you have a Post model.