Пример #1
0
 /**
  * @return WF_Application_Request
  */
 public static function Instance()
 {
     if (!self::$_instance) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
Пример #2
0
 /**
  * 输出js
  */
 public function js()
 {
     $baseUrl = WF_Application_Request::Instance()->getBaseUrl();
     foreach ($this->_js as $js) {
         echo '<script type="text/javascript" src="' . $baseUrl . $js . '"></script>' . "\n";
     }
 }
Пример #3
0
 /**
  * 对请求进行分发
  * 
  * @param WF_Application_Request $request
  * @param WF_Application_Response $response
  */
 public static function dispath(WF_Application_Request $request, WF_Application_Response $response)
 {
     //实例化出应该调用的 contrller
     $dir = $request->getDirectory();
     $controller_key = $request->getController();
     $controller_name = ucfirst($controller_key) . 'Controller';
     $action = $request->getAction();
     $hierarchy = $request->getDirectory() === 'default' ? '' : $dir . '/';
     $controller_file = APP_PATH . '/app/' . $hierarchy . 'controller/' . $controller_key . '.php';
     require $controller_file;
     $controller = new $controller_name();
     $controller->init();
     //调用action
     $ifRender = $controller->{$action}();
     /**
      * 如果需要进行渲染则 启用View引擎, 使用何种View 引擎可以在配置中进行配置
      */
     if ($ifRender === null) {
         $view = WF_Application_View_Manager::GetView();
         if ($controller->view) {
             foreach ($controller->view as $key => $value) {
                 $view->{$key} = $value;
             }
         }
         //找到相应的tpl
         $tpl = $view->getTpl();
         if ($tpl) {
             $tplfile = APP_PATH . '/app/' . $hierarchy . 'views/' . $controller_key . '/' . $tpl . '.phtml';
         } else {
             $tplfile = APP_PATH . '/app/' . $hierarchy . 'views/' . $controller_key . '/' . $action . '.phtml';
         }
         $view->setTplFile($tplfile);
         //如果设置了layout 找到相应的layout 文件
         $layout = $view->getLayout();
         if ($layout) {
             $layoutFile = APP_PATH . '/app/' . $hierarchy . 'views/' . $layout . '.phtml';
         } else {
             $layoutFile = APP_PATH . '/app/' . $hierarchy . 'views/layout.phtml';
         }
         $view->setLayoutFile($layoutFile);
         $view->render($response);
     }
 }
Пример #4
0
 /**
  * 生成 默认的路由 url
  * @param unknown_type $controller
  * @param unknown_type $action
  * @param unknown_type $dir
  * @param unknown_type $params
  * 
  * @author Rocky
  */
 private function _defaultUrl($controller, $action, $dir = null, $params = null)
 {
     $rtn = "";
     $rtn .= WF_Application_Request::Instance()->getBaseUrl();
     if ($dir != null) {
         $rtn .= $dir . '/';
     }
     $rtn .= $controller;
     $rtn .= '/' . preg_replace('/-(\\w)/ie', 'strtoupper(\'$1\')', $action);
     if (is_array($params)) {
         foreach ($params as $key => $value) {
             $rtn .= '/' . $key . '/' . $value;
         }
     }
     return $rtn;
 }
Пример #5
0
 private function _initACD()
 {
     $request = WF_Application_Request::Instance();
     $this->action = $request->getAction();
     $this->controller = $request->getController();
     $this->dir = $request->getDirectory();
 }
Пример #6
0
 private static function _dispathError()
 {
     $request = WF_Application_Request::Instance();
     $response = WF_Application_Response::Instance();
     $request->setAction("index");
     $request->setController("error");
     $request->setDirectory("default");
     $response->setCode(500);
     WF_Application_Dispather::dispath($request, $response);
 }