Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.14 KB | None | 0 0
  1. <?php
  2. require_once(APPPATH.'/libraries/LayoutParser'.EXT);
  3. class Layout {
  4.    
  5.     protected static $layoutParser;
  6.    
  7.     protected $layoutBlock;
  8.     protected $controllerObject;
  9.     protected $controllerActionName;
  10.    
  11.     public function _setControllerActionName($controllerActionName = ''){
  12.         $controllerActionName = preg_replace('/\//', '_', $controllerActionName);
  13.         $controllerActionName = trim($controllerActionName , '_');
  14.         $this->controllerActionName = $controllerActionName;
  15.         echo var_dump($controllerActionName);
  16.         $this->layoutBlock = &self::$layoutParser->getActionLayout( $this->controllerActionName );
  17.     }
  18.    
  19.     public function _getControllerLayout(){
  20.         return var_dump($this->layoutBlock);
  21.     }
  22.    
  23.     public function _getTemplate(){
  24.         return $this->layoutBlock['template'];     
  25.     }
  26.    
  27.     public function _getChildController($childName){
  28.         if(!is_array($this->layoutBlock['child_blocks']))
  29.             return null;
  30.            
  31.         $childLayout = null;
  32.         foreach( $this->layoutBlock['child_blocks'] as &$val ){
  33.             if( strcmp($val['name'], $childName) === 0){
  34.                 $childLayout = &$val;
  35.                 break;
  36.             }
  37.         }
  38.        
  39.         if($childLayout === null)
  40.             return null;
  41.            
  42.         require_once APPPATH . 'controllers/' . strtolower($childLayout['controller']) . EXT;
  43.         $childController = New $childLayout['controller']();
  44.         $childController->_setLayout($childLayout);
  45.        
  46.         return $childController;
  47.     }
  48.    
  49.     public function _appendChild($childName){
  50.         $childController = &$this->_getChildController($childName);
  51.         if($childController !== null)
  52.             $childController->_doAction();     
  53.     }
  54.    
  55.     public function _doAction(){
  56.         $this->layoutBlock;
  57.         $this->{ $this->layoutBlock['action'] }();
  58.     }
  59.    
  60.     public function __construct(&$controllerObject = NULL , &$layout = NULL){
  61.         if($layout === NULL){
  62.             self::$layoutParser = LayoutParser::getInstance();
  63.             $this->layoutBlock = &self::$layoutParser->getLayout();
  64.         }
  65.         else {
  66.             $this->layoutBlock = &$layout;
  67.         }
  68.        
  69.         if($controllerObject !== NULL){
  70.             $this->controllerObject = $controllerObject;
  71.         }
  72.     }
  73.  
  74.     public function _setLayout(&$layout){
  75.         $this->layoutBlock = &$layout;
  76.     }
  77.    
  78.     public function _initControllerLayout(){
  79.        
  80.     }
  81. }
  82.  
  83. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement