public function postDispatch(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response) { # 得到 body 代码 $body = $response->getBody(); # 清理 body $response->clearBody(); # 使用 布局 $layout = new Yaf_View_Simple($this->_layoutDir); $layout->content = $body; /* if(false !== strpos(REDIRECT_URL, '/loan_')){ $loan = LoanModel::getInfoByUid($_SESSION['user']['uid']); if(empty($loan)){ $loan = array( 'loan_total' => 0, 'deposit_total' => 0, 'loan_over'=> 0, 'ybc_over' => 0, 'loan_lock'=> 0, 'ybc_lock' => 0 ); } $layout->assign('loan', $loan); } */ $layout->assign('layout', $this->_layoutVars); $response->setBody($layout->render($this->_layoutFile)); }
public function postDispatch(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response) { /* get the body of the response */ $body = $response->getBody(); /*clear existing response*/ $response->clearBody(); /* wrap it in the layout */ $layout = new Yaf_View_Simple($this->_layoutDir); $layout->content = $body; $layout->assign('layout', $this->_layoutVars); /* set the response to use the wrapped version of the content */ $response->setBody($layout->render($this->_layoutFile)); }
public function postDispatch(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response) { if (!Yaf_Registry::get("disableLayout")) { //获取已经设置响应的Body $body = $response->getBody(); //清除已经设置响应的body $response->clearBody(); $layout = new YoloYafView($this->_layoutDir); $layout->content = $body; //self::assign('companyInfo', UserApi::singleton()->getCompanyInfo(WZhaopinEnv::getCompanyWid())); $layout->assign('layout', self::$_layoutVars); //设置响应的body $response->setBody($layout->render((Yaf_Registry::get("setLayout") ? Yaf_Registry::get("setLayout") : $this->_layoutFile) . '.phtml')); } }
private function handle(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response, Yaf_View_Interface $view) { $request->setDispatched(true); $app = $this->getApplication(); $appDir = $app->getAppDirectory(); if ($appDir == '') { throw new Yaf_Exception_StartupError('Yaf_Dispatcher requires ' . 'Yaf_Application(which set the application.directory) ' . 'to be initialized first.'); } $module = $request->getModuleName(); if (empty($module)) { throw new Yaf_Exception_DispatchFailed('Unexcepted an empty module name'); } if (!Yaf_Application::isModuleName($module)) { throw new Yaf_Exception_LoadFailed_Module('There is no module ' . $module); } $controllerName = $request->getControllerName(); if (empty($controllerName)) { throw new Yaf_Exception_DispatchFailed('Unexcepted an empty controller name'); } $className = $this->getController($appDir, $module, $controllerName); if (!$className) { return false; } $controller = new $className($request, $response, $view); if (!$controller instanceof Yaf_Controller_Abstract) { throw new Yaf_Exception_TypeError('Controller must be an instance of Yaf_Controller_Abstract'); } $viewDir = $view->getScriptPath(); //template dir might be set from the __construct if (empty($viewDir)) { $templateDir = ''; if ($this->_default_module == $module) { $templateDir = $appDir . DIRECTORY_SEPARATOR . Yaf_Loader::YAF_VIEW_DIRECTORY_NAME; } else { $templateDir = $appDir . DIRECTORY_SEPARATOR . Yaf_Loader::YAF_MODULE_DIRECTORY_NAME . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . Yaf_Loader::YAF_VIEW_DIRECTORY_NAME; } $view->setScriptPath($templateDir); unset($templateDir); } $action = $request->getActionName(); $actionMethod = $action . 'Action'; if (method_exists($controller, $actionMethod)) { //Get all action method parameters $methodParams = $this->getActionParams($className, $actionMethod); if (null == $methodParams) { $ret = call_user_func(array($controller, $actionMethod)); } else { $ret = call_user_func_array(array($controller, $actionMethod), $this->prepareActionParams($request, $methodParams)); } if (is_bool($ret) && $ret == false) { return true; } } elseif (($actionController = $this->getAction($appDir, $controller, $action, $module)) != null) { //check if not in actions vars we have the action $actionMethod = 'execute'; if (method_exists($actionController, $actionMethod)) { //Get all action method parameters $methodParams = $this->getActionParams(get_class($actionController), $actionMethod); $ret = null; if (null == $methodParams) { $ret = call_user_func(array($actionController, $actionMethod)); } else { $ret = call_user_func_array(array($actionController, $actionMethod), $this->prepareActionParams($request, $methodParams)); } if (is_bool($ret) && $ret == false) { return true; } } else { throw new Yaf_Exception_LoadFailed_Action('There is no method ' . $actionMethod . ' in ' . get_class($controller) . '::$actions'); } } else { return false; } if ($this->_auto_render == true) { if ($this->_instantly_flush == true) { $controller->display($action); } else { $ret = $controller->render($action); $response->setBody($ret); } } $controller = null; }
private function handle(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response, Yaf_View_Interface $view) { $request->setDispatched(true); $app = $this->getApplication(); $module = $request->getModuleName(); if (empty($module)) { throw new Yaf_Exception('Unexcepted an empty module name'); return false; } $controllerName = $request->getControllerName(); if (empty($controllerName)) { throw new Yaf_Exception('Unexcepted an empty controller name'); return false; } $className = $this->getController($module, $controllerName); if (!$className) { return false; } $controller = new $className($request, $response, $view); if (!$controller instanceof Yaf_Controller) { throw new Yaf_Exception('Controller must be an instance of Yaf_Controller'); return false; } $action = $request->getActionName(); $actionMethod = $action . 'Action'; if (!method_exists($controller, $actionMethod)) { throw new Yaf_Exception($className . '::' . $actionMethod . ' not exists!'); return false; } $ret = call_user_func(array($controller, 'actionBefore')); if ($ret === false) { return false; } $ret = call_user_func(array($controller, $actionMethod)); if ($ret === false) { return false; } $ret = call_user_func(array($controller, 'actionAfter')); if ($ret === false) { return false; } if ($this->_auto_render == true) { $response->setBody($controller->render($action)); } $controller = null; }