/** * 处理 do * 有可能会返回 goToDo * * 只有一个单词的do,对应的action是 index * * * @param string $do * @return string $goToDo */ protected function processDo($do, $defaultView = "Html") { if ($do == "") { $e = new Watt_Exception(Watt_I18n::trans("ERR_DISPATCH_NODO")); throw $e; } $goToDo = ""; $arrCtrlAndAction = $this->_analyzeDoToControllerAndAction($do); $controller = $arrCtrlAndAction[0]; $action = $arrCtrlAndAction[1]; $doFile = $arrCtrlAndAction[2]; $doAction = $arrCtrlAndAction[3]; //exit( $doFile . "|" . $doAction ); //使用 ob_start 是为了Controller里的 redirect 可以正常使用 if (defined('ENABLE_CTRL_BUFFER') && ENABLE_CTRL_BUFFER) { /** * 为了不让服务器过长等待时间,改为不启用Ctrl Buffer * @author terry * @version 0.1.0 * Mon Jan 14 14:41:39 CST 2008 */ ob_start(); } /** * 增加了对页面缓存的支持 */ $cache = null; Watt_Debug::addInfoToDefault('Begin create action [' . $controller . '] [' . $action . ']'); $theCtrl = Watt_Controller_Action::factory($controller, $action); Watt_Debug::addInfoToDefault('After create action'); $viewMenu = isset($_REQUEST["view_menu"]) ? trim($_REQUEST["view_menu"]) == '0' ? false : true : true; $theCtrl->setNeedMenu($viewMenu); $actionCacheTime = $theCtrl->getActionCacheTime($action); if ($actionCacheTime > 0) { $cache = new Watt_Cache($actionCacheTime); if ($cache->cacheCheck()) { //如果符合缓存条件,则会读取缓存文件,并 exit. /** * 改为退出处理,为了记录页面执行时间。 * 这里一定不能 return true. * @author terry * @version 0.1.0 * Mon Jan 14 14:30:43 CST 2008 */ return ''; } } /** * 检查 会话的权限。 * 如果没有权限,抛出一个异常 * 此处别扭 */ $rbac = new Watt_Rbac(); //$rbac->checkSession(Watt_Session::getSession(), $do); $privilege = $rbac->checkActionPrivilege(Watt_Session::getSession(), $theCtrl, $action); if (is_object($privilege) && $privilege instanceof TpmYonghuzhaoquanxian) { if (!$theCtrl->getTitle()) { $theCtrl->setTitle(Watt_I18n::trans($privilege->getQxMingcheng())); } } Watt_Debug::addInfoToDefault('', 'Pre do action..'); if (method_exists($theCtrl, $doAction)) { //执行controller中的action $theCtrl->{$doAction}(); } else { throw new Exception(Watt_I18n::trans("ERR_APP_LOST_ACTION")); } Watt_Debug::addInfoToDefault('', 'After do action..'); $goToDo = $theCtrl->getGoToDo(); $data = $theCtrl->getData(); /** * 改为对 Ctrl 不进行 Buffer 的处理 * @author terry * @version 0.1.0 * Mon Jan 14 15:05:28 CST 2008 */ if (defined('ENABLE_CTRL_BUFFER') && ENABLE_CTRL_BUFFER) { if (defined("DEBUG") && DEBUG) { //调试阶段才显示Controller里输出的信息 echo ob_get_clean(); } else { //用户使用阶段不允许 action 里输出显示数据 ob_clean(); } } if ($theCtrl->isNeedView()) { Watt_Debug::addInfoToDefault('', 'Pre load view..'); if ($theCtrl->getViewType()) { $defaultView = $theCtrl->getViewType(); } /** * 创建一个View。将来可以用不同的View代替此View */ //$view = Watt_View::factory( "Html", Watt_Config::getViewPath() ); $view = Watt_View::factory($defaultView, Watt_Config::getViewPath()); $view->setHeader($theCtrl->getHeader()); Watt_Debug::addInfoToDefault('', 'After view factory..'); /** * 读取菜单应该由View来判断 * @author terry * Thu Jul 22 10:46:07 CST 2010 */ if ($theCtrl->isNeedMenu() && strtolower($defaultView) == 'html') { //$theCtrl->isNeedCaidan(); /** * 如果用户已登录,读取菜单信息 * @todo 未登录可能也可以有菜单 */ if ($user_id = Watt_Session::getSession()->getUserId()) { $tpmCaidans = TpmCaidanPeer::getJueseCaidan(Watt_Session::getSession()->getRoleId()); if (count($tpmCaidans)) { $view->setHeader($tpmCaidans, "menu"); } } //读取菜单完 } //$view->renderModel($theCtrl); $view->renderView($data, $this->_getDefaultViewFileOfAction($controller, $action), true); } /** * 与开始的Cache对应 */ if ($actionCacheTime > 0 && $cache instanceof Watt_Cache) { $cache->caching(); } return $goToDo; }