Guest User

Untitled

a guest
Feb 18th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.28 KB | None | 0 0
  1. class MyController extends ActionController
  2. {
  3.     /* ... */
  4.     public feedAction()
  5.     {
  6.         $this->getEvent()->setParam('disableLayout', true);
  7.     }
  8.     /* ... */
  9. }
  10.  
  11. class View\Listener
  12. {
  13.     public function attach(EventCollection $events)
  14.     {
  15.         $this->listeners[] = $events->attach('dispatch.error', array($this, 'renderError'));
  16.         $this->listeners[] = $events->attach('dispatch', array($this, 'render404'), -80);
  17.         $this->listeners[] = $events->attach('dispatch', array($this, 'setLayout'), -999);
  18.         $this->listeners[] = $events->attach('dispatch', array($this, 'renderLayout'), -1000);
  19.     }
  20.  
  21.     /**
  22.      * Make some decisions regarding the layout just before redering it
  23.      *
  24.      * @param MvcEvent $e
  25.      */
  26.     public function setLayout(MvcEvent $e)
  27.     {
  28.         if ($e->getParam('layout')) {
  29.             $this->layoutScript = $e->getParam('layout');
  30.  
  31.         } elseif ($e->getParam('layout') === false) {
  32.             $e->stopPropagation();
  33.             $response = $e->getResponse();
  34.             if (!$response) {
  35.                 $response = new Response();
  36.                 $e->setResponse($response);
  37.             }
  38.  
  39.             $response->setContent($e->getResult());
  40.  
  41.             return $response;
  42.         }
  43.     }
  44. }
Add Comment
Please, Sign In to add comment