/** * 处理 do * 有可能会返回 goToDo * * 只有一个单词的do,对应的action是 index * * * @param string $do * @return string $goToDo */ protected function processDo($do, $defaultView = "Html") { if ($do == "") { $e = new Pft_Exception(Pft_I18n::trans("ERR_DISPATCH_NODO")); throw $e; } $goToDo = ""; $arrCtrlAndAction = $this->_analyzeDoToControllerAndAction($do); $controller = $arrCtrlAndAction[0]; $action = $arrCtrlAndAction[1]; $doFile = $arrCtrlAndAction[2]; $doAction = $arrCtrlAndAction[3]; //使用 ob_start 是为了Controller里的 redirect 可以正常使用 //ob_start(); $theCtrl = Pft_Controller_Action::factory($controller, $action); /** * 检查 会话的权限。 * 如果没有权限,抛出一个异常 * 此处别扭 */ $rbac = new Pft_Rbac(); //$rbac->checkSession(Pft_Session::getSession(), $do); $privilege = $rbac->checkActionPrivilege(Pft_Session::getSession(), $theCtrl, $action); if ($privilege instanceof TpmYonghuzhaoquanxian) { if (!$theCtrl->getTitle()) { $theCtrl->setTitle(Pft_I18n::trans($privilege->getQxMingcheng())); } } Pft_Debug::addInfoToDefault('', 'Pre do action.'); if (method_exists($theCtrl, $doAction)) { //执行controller中的action $theCtrl->{$doAction}(); } else { throw new Exception(Pft_I18n::trans("ERR_APP_LOST_ACTION")); } Pft_Debug::addInfoToDefault('', 'After do action..'); $goToDo = $theCtrl->getGoToDo(); $data = $theCtrl->getData(); if (defined("DEBUG") && DEBUG) { //调试阶段才显示Controller里输出的信息 //echo ob_get_clean(); } else { //用户使用阶段不允许 action 里输出显示数据 //ob_clean(); } if ($theCtrl->isNeedView()) { Pft_Debug::addInfoToDefault('', 'Pre load view..'); if ($theCtrl->getViewType()) { $defaultView = $theCtrl->getViewType(); } $view = Pft_View::factory($defaultView, Pft_Config::getViewPath()); $view->setHeader($theCtrl->getHeader()); Pft_Debug::addInfoToDefault('', 'After view factory..'); /** * 如果用户已登录,读取菜单信息 * @todo 未登录可能也可以有菜单 */ if ($user_id = Pft_Session::getSession()->getUserId()) { $tpmCaidans = TpmCaidanPeer::getJueseCaidan(Pft_Session::getSession()->getRoleId()); if (count($tpmCaidans)) { $view->setHeader($tpmCaidans, "menu"); // $menus = array(); // foreach ( $tpmCaidans as $tpmCaidan ) // { // $menus[] = array( $tpmCaidan->getCdMingcheng() // , $tpmCaidan->getCdChuliye() // ); // } // $view->setHeader( $menus, "menu" ); } } //读取菜单完 //$view->renderModel($theCtrl); $view->renderView($data, $this->_getDefaultViewFileOfAction($controller, $action), true); } return $goToDo; }