コード例 #1
0
ファイル: View.php プロジェクト: h1soft/h
 public function render($filename = false, $data = false, $output = true)
 {
     $actionName = strtolower(rtrim(Application::app()->router()->getActionName(), 'Action'));
     if (is_array($data)) {
         $this->_hdata = array_merge($this->_hdata, $data);
     }
     if (empty($filename)) {
         $filename = $actionName;
     }
     if (is_array($filename) && is_bool($data)) {
         if (!$data) {
             $output = false;
         }
         $data = array_merge($this->_hdata, $filename);
         $filename = sprintf("%s/%s.php", strtolower(Application::app()->router()->getControllerName()), $actionName);
     }
     $this->tplRealPath = sprintf("%s%s.php", $this->getViewPath(), $filename);
     $this->setTemplateFileName($filename);
     if (!is_file($this->tplRealPath)) {
         throw new \Exception("模版不存在 {$this->tplRealPath}");
     }
     return $this->tplRealPath;
 }
コード例 #2
0
ファイル: Controller.php プロジェクト: h1soft/h
 public function getFlashMessage($default = "")
 {
     $message = Application::session()->get('hflash');
     Application::session()->remove('hflash');
     Application::session()->remove('hcode');
     return $message ? $message : $default;
 }
コード例 #3
0
ファイル: Twig.php プロジェクト: h1soft/h
 private function initFunctions()
 {
     $link_to = new \Twig_SimpleFunction('link_to', function ($_url, $_params = NULL) {
         return url_to($_url, $_params);
     });
     $this->_twigEnv->addFunction($link_to);
     $url_for = new \Twig_SimpleFunction('url_to', function ($_url, $_params = NULL) {
         return url_to($_url, $_params);
     });
     $this->_twigEnv->addFunction($url_for);
     $repeat = new \Twig_SimpleFunction('repeat', function ($_str, $_num = 0) {
         return str_repeat($_str, $_num);
     });
     $this->_twigEnv->addFunction($repeat);
     $url_ref = new \Twig_SimpleFunction('urlRef', function () {
         $rtn = Application::session()->get('hurlref');
         return $rtn ? $rtn : Application::app()->request()->curUrl();
     });
     $this->_twigEnv->addFunction($url_ref);
     $flash = new \Twig_SimpleFunction('flash', function ($_remove = true) {
         $flashmessage = Application::session()->get('hflash');
         if ($_remove) {
             Application::session()->remove('hflash');
         }
         return $flashmessage;
     });
     $this->_twigEnv->addFunction($flash);
     $flashCode = new \Twig_SimpleFunction('flashCode', function ($_remove = true) {
         $hcode = Application::session()->get('hcode');
         if ($_remove) {
             Application::session()->remove('hcode');
         }
         return $hcode;
     });
     $this->_twigEnv->addFunction($flashCode);
     $dateFormat = new \Twig_SimpleFunction('dateFormat', function ($_timestamp = NULL, $format = 'Y-m-d') {
         if ($_timestamp) {
             return date($format, $_timestamp);
         } else {
             return NULL;
         }
     });
     $this->_twigEnv->addFunction($dateFormat);
 }