Last active
          November 12, 2019 02:07 
        
      - 
      
- 
        Save darylteo/0fb8cc59dbcc62c90d1b81502408b7c4 to your computer and use it in GitHub Desktop. 
    Custom_Controller_Plugin_Layout.php
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | <?php | |
| public function postDispatch(Zend_Controller_Request_Abstract $request) | |
| { | |
| $layout = Zend_Layout::getMvcInstance(); | |
| // Return early if forward detected | |
| if (!$request->isDispatched() | |
| || $this->getResponse()->isRedirect() | |
| || ($layout->getMvcSuccessfulActionOnly() | |
| && (!empty($helper) && !$helper->isActionControllerSuccessful()))) | |
| { | |
| return; | |
| } | |
| // Return early if layout has been disabled | |
| if (!$layout->isEnabled()) { | |
| return; | |
| } | |
| if ($layout->getLayout() !== 'layout2018') { | |
| return; | |
| } | |
| $response = $this->getResponse(); | |
| $fullContent = null; | |
| $obStartLevel = ob_get_level(); | |
| try { | |
| // hack to output header first | |
| $layout->setLayout('layout2018head'); | |
| $fullContent = $layout->render(); | |
| // set it back to original value for original behaviour. | |
| $layout->setLayout('layout2018'); | |
| } catch (Exception $e) { | |
| while (ob_get_level() > $obStartLevel) { | |
| $fullContent .= ob_get_clean(); | |
| } | |
| $request->setParam('layoutFullContent', $fullContent); | |
| $request->setParam('layoutContent', $layout->content); | |
| $response->setBody(null); | |
| throw $e; | |
| } | |
| ob_end_flush(); | |
| // output header immediately | |
| echo $fullContent; | |
| flush(); | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
https://github.com/zendframework/zf1/blob/136735e776f520b081cd374012852cb88cef9a88/library/Zend/Layout/Controller/Plugin/Layout.php#L108