Example #1
0
 /**
  * Sets the layout to load. This will only set if the layout exists.
  * 
  * @access protected
  * @final
  * @param string $name The name of the layout to load
  * @param string $branch Optional The branch to load the layout from assumes the current if none is defined
  * @return boolean true if the layout was set and boolean false if not
  */
 protected final function _setLayout($name, $branch = '')
 {
     $layout = array('name' => $name, 'branch' => $branch);
     // call hook
     Hook::call('Controller.setLayout.before', array(&$layout));
     if ($layout['branch'] == Reg::get('System.rootIdentifier') || !Reg::hasVal("Branch.name") && empty($layout['branch'])) {
         $path = Reg::get("Path.physical") . "/views/layouts/" . Config::uriToFile(Config::methodToFile($layout['name'])) . ".php";
         // call hook
         Hook::call('Controller.setLayout.setPath', array(&$layout, &$path));
         if (file_exists($path)) {
             $this->layout = $path;
             $return = true;
         } else {
             $return = false;
         }
     } else {
         if (Reg::hasVal("Branch.name") && empty($layout['branch']) || !empty($layout['branch'])) {
             if (!empty($layout['branch'])) {
                 $branchToUse = $layout['branch'];
             } else {
                 $branchToUse = Reg::get("Branch.name");
             }
             $path = Reg::get("Path.physical") . "/branches/" . Config::uriToFile(Config::classToFile($branchToUse)) . "/views/layouts/" . Config::uriToFile(Config::methodToFile($layout['name'])) . ".php";
             // call hook
             Hook::call('Controller.setLayout.setPath', array(&$layout, &$path));
             if (file_exists($path)) {
                 $this->layout = $path;
                 $return = true;
             } else {
                 $return = false;
             }
         } else {
             $return = false;
         }
     }
     // call hook
     Hook::call('Controller.setLayout.after', array(&$return));
     return $return;
 }