Zf2 Naviagation Custom Active Page Call in layout/view $nav = $this->navigation('Navigation'); $pages = $nav->getContainer()->getPages(); foreach ($pages as $page) { if ($page->getId() == 'admin') { $page->setActive(true); } }
In this article I will show a simple way to log every change to doctrine 2 entity. This one will not be copy / paste. Just check out the code and help yourself. 1. Create event service /** * @developer Ivan Gospodinow */ namespace Application\Service; use Application\Entity\DbLogEntity; use Application\Entity\AbstractEntity; use Doctrine\Common\Persistence\Event\LifecycleEventArgs; use \DateTime; class DoctrineLogChangesService […]
How to change layout for ajax requests in Zend Framework 2 1. Module.php public function onBootstrap(MvcEvent $e) { $e->getApplication() ->getEventManager() ->getSharedManager() ->attach( 'Zend\Mvc\Controller\AbstractController', 'dispatch', function ($e) { $controller = $e->getTarget(); if ($controller->getRequest() instanceof HttpRequest) { if ($controller->getRequest()->isXmlHttpRequest()) { $controller->layout('layout/ajax'); } } }, 100 ); } 2. module.config.php Add the layout path 'view_manager' => array( 'template_map' […]
Module.php public function getConfig() { return (include __DIR__ . '/config/module.config.php') + (include __DIR__ . '/config/module.config.permissions.php'); } Simple as that.
Long time no ZF2 post, but here is something interesting peace of code that can solve cache problems present in most of the projects. I am assuming that, the reader knows how to create custom cache Factory in ZF2. Step 1. Edit your existing cache factory. See Line 35. namespace Application\Factory; use Application\Factory\CacheProxy; // Or […]
This post is a follow up from : zend framework 2 acl in 5 minutes Step 1 Code in config/autoload/global.php 'navigation' => array( 'default'=> array( array( 'label' => 'Home', 'route' => 'home', 'resource'=> 'home', ), array( 'label' => 'Login', 'route' => 'login', 'resource'=> 'login', ), array( 'label' => 'Register', 'route' => 'register', 'resource'=> 'register', ), […]
In this tutorial you will learn how to setup zend framework 2 acl and check if user has access for current route. If you don`t have testing project , download one from here. Add file module.acl.roles in application/config/ Tip: In fact role resources may be zend framework 2 routes. return array( 'guest'=> array( 'home', 'login', […]
There is a easy way to get zend framework 2 base path with domain name in layout. 1. In layout.phtml $homeUrl = $this->url('home',array(),array('force_canonical' => true)); 2.Adding home route in module.config.php 'home' => array( 'type' => 'Zend\Mvc\Router\Http\Literal', 'options' => array( 'route' => '/', 'defaults' => array( 'controller' => 'Application\Controller\Index', 'action' => 'index', ), ), ), Simple […]
In Zend Framework 2 , layout can be easily changed from module based on controller(name). Step 1. Add in module.config.php file 'controller_layouts' => array( 'MyControllerName' => 'layout/MyControllerName', ), and 'view_manager' => array( //more options 'template_map' => array( 'layout/MyControllerName'=> PATH_TO_TEMPLATE ), ), Step 2. Add in module.php $e->getApplication()->getEventManager()->getSharedManager() ->attach('Zend\Mvc\Controller\AbstractActionController', 'dispatch', function($e) { $controller = $e->getTarget(); […]