Example #1
0
 protected function display($tpl = null)
 {
     if (is_null($tpl)) {
         $tpl = $this->method;
     }
     $this->tpl = $tpl;
     if (Application::$act == $this->act && Application::$mod == $this->method) {
         Application::$tpl = $tpl;
     } else {
         $GLOBALS['_FileCount']++;
         return;
     }
     $content = file_get_contents(APP_TPL . Application::$controller_obj->act . '/' . Application::$tpl . '.html');
     //parse include
     $ret = preg_match_all('/<\\{\\s*include\\s*=\\s*"(.*?)"\\}>/i', $content, $match);
     if ($ret) {
         foreach ($match[1] as $k => $v) {
             $tArr = explode('/', $v);
             $act_name = ucfirst($tArr[0] . 'Action');
             $act_name = new $act_name();
             $act_name->{$tArr}[1]();
             unset($tArr);
         }
     }
     if (is_array(Application::$controller_obj->valArr) && !empty(Application::$controller_obj->valArr)) {
         foreach (Application::$controller_obj->valArr as $k => $v) {
             ${$k} = $v;
         }
         unset(Application::$controller_obj->valArr);
     }
     $GLOBALS['_FileCount']++;
     require_once load_tpl(APP_TPL . Application::$controller_obj->act . '/' . Application::$tpl . '.html', Application::$controller_obj->open_token);
 }
Example #2
0
 protected function display($tpl = null)
 {
     $suffix = C('template-suffix');
     $mood = $GLOBALS['_Module'];
     if (self::$is_smarty === true) {
         if (is_null($tpl)) {
             if (empty($this->act)) {
                 $templates = Application::$act;
             } else {
                 $templates = $this->act;
             }
             $temp = debug_backtrace();
             if (isset($temp[1]['function']) && !empty($temp[1]['function'])) {
                 $tpl = $temp[1]['function'];
             } elseif (!empty($this->method)) {
                 $tpl = $this->method;
             } else {
                 $tpl = Application::$mod;
             }
             unset($temp);
         } else {
             $arr = explode('/', $tpl);
             $cnt = count($arr);
             if ($cnt == 1) {
                 //这种格式为index
                 if (empty($this->act)) {
                     $templates = Application::$act;
                 } else {
                     $templates = $this->act;
                 }
                 $tpl = $arr[0];
             } elseif ($cnt == 2) {
                 //这种格式为Index/index
                 $templates = $arr[0];
                 $tpl = $arr[1];
             } elseif ($cnt == 3) {
                 //这种格式为Index/Index/index
                 $mood = $arr[0];
                 $templates = $arr[1];
                 $tpl = $arr[2];
             } else {
                 //否则就出错了
                 SL('Template file format error', '设置的Template: ' . $tpl . ' format error', '访问日志', 1);
                 if (APP_DEBUG) {
                     die('Template file format error');
                 }
             }
         }
         $this->smarty->setTemplateDir(APP_TPL . $mood . DS . $templates . DS);
         spl_autoload_unregister('my_autoload');
         $this->smarty->display($tpl . '.' . $suffix);
     } else {
         if (is_null($tpl)) {
             $tpl = $this->method;
         }
         $this->tpl = $tpl;
         if (Application::$act == $this->act && Application::$mod == $this->method) {
             Application::$tpl = $tpl;
         } else {
             $GLOBALS['_FileCount']++;
             return;
         }
         $content = file_get_contents(APP_TPL . $mood . DS . Application::$controller_obj->act . DS . Application::$tpl . '.' . $suffix);
         //parse include
         $ret = preg_match_all('/' . C('template-left_delimiter') . '\\s*include\\s*=\\s*"(.*?)"' . C('template-right_delimiter') . '/i', $content, $match);
         if ($ret) {
             foreach ($match[1] as $k => $v) {
                 $tArr = explode('/', $v);
                 $act_name = ucfirst($tArr[0] . 'Action');
                 $act_name = new $act_name();
                 $act_name->{$tArr}[1]();
                 unset($tArr);
             }
         }
         if (is_array(Application::$controller_obj->valArr) && !empty(Application::$controller_obj->valArr)) {
             foreach (Application::$controller_obj->valArr as $k => $v) {
                 ${$k} = $v;
             }
             unset(Application::$controller_obj->valArr);
         }
         $GLOBALS['_FileCount']++;
         require_once load_tpl(APP_TPL . $mood . DS . Application::$controller_obj->act . DS . Application::$tpl . '.' . $suffix, Application::$controller_obj->open_token);
     }
 }