| <?php | 
| //af_Loader::import('/core/BaseController'); | 
| /** | 
|  * 后台通用控制器 加了rbac | 
|  * Class AdminCommonController | 
|  */ | 
| class System_Controller_Admin extends System_Controller_Base{ | 
|   | 
|     public $layout = APP_ROOT.'/modules/Admin/views/layout/adminLayout.phtml'; | 
|     public $defaultMsgTemplate = 'common/showmsg.phtml'; | 
|     public $config = array(); | 
|     public $session = array(); | 
|     /** | 
|      * @var boolean 是否开启用户验证 authenticate | 
|      */ | 
|     public $doAuth = true; | 
|     /** | 
|      * @var bool 是否检查权限 | 
|      */ | 
|     public $checkAuthorization = true; | 
|   | 
|     /** | 
|      * @var string 当前请求的权限节点 | 
|      */ | 
|     public $currentRequest = ''; | 
|   | 
|     public function init(){ | 
|         $this->session = Yaf_Session::getInstance(); | 
|         if(!$this->session->has('user')){ | 
|           $this->redirect('/user_login.html'); | 
|         } | 
|         //初始化redis | 
|         $this->redis = System_Service_Locator::getInstance()->get('redis'); | 
|         if(!$this->redis->exists('modules') ){ | 
|           $this->redis->set('modules', $this->getModules()); | 
|         } | 
|          //更新角色权限 | 
|         if(!$this->redis->exists('role_auth')){ | 
|           Util::updateRoleAuth(); | 
|         } | 
|         $role_auth = $this->redis->get('role_auth'); | 
|         $module_service = new Service_Module(); | 
|        // $current_module = $module_service->getModuleInfo(array('module' => strtolower($this->_request->module), 'controller' => strtolower($this->_request->controller), 'action' => strtolower($this->_request->action))); | 
|        // if($current_module){ | 
|        //   if(!in_array($current_module['_id'], $role_auth[$this->session['user']['role_id']])){ | 
|        //     $this->redirect('/error/show/type/no_auth'); | 
|        //   } | 
|       //  } | 
|        // else{ | 
|        //    $this->redirect('/error/show/type/not_found'); | 
|        // } | 
|         parent::init(); | 
|        // $currentRequest = '/' . strtolower( implode('/', [ | 
|        ///         $this->_request->module, | 
|        //         $this->_request->controller, | 
|        //         $this->_request->action, | 
|        //     ]) ); | 
|        // $this->getView()->currentRequest = $currentRequest; | 
|       //  if($this->checkAuthorization && $this->userInfo){ | 
|        //     $rbacManage = \Core\ServiceLocator::getInstance()->get('rbacManage'); | 
|       //      if( ! $rbacManage->isAdmin( $this->userInfo['name'] ) ) { | 
|        //         $authInfo = $rbacManage->checkAuthorization($this->userInfo['id'], $currentRequest); | 
|        //         if ($authInfo == false) { | 
|         //            throw new \Exception('没有节点访问权限'); | 
|          //       } | 
|        //     } | 
|         //} | 
|     } | 
|   | 
|     public function setLayout($layout = ''){ | 
|         $this->layout = $layout; | 
|     } | 
|   | 
|     /** | 
|      * 返回正确提示 | 
|      * @param  string  $content [description] | 
|      * @param  boolean $is_json [description] | 
|      * @return [type]           [description] | 
|      */ | 
|     public function showSuccess($content = '', $is_json = false){ | 
|       return $this->showMessage($content, 200, $is_json); | 
|     } | 
|   | 
|     /** | 
|      * 返回错误信息 | 
|      * @param  string  $content [description] | 
|      * @param  integer $code    [description] | 
|      * @param  boolean $is_json [description] | 
|      * @return [type]           [description] | 
|      */ | 
|     public function showError($content = '', $code = 400, $is_json = false){ | 
|       return $this->showMessage($content, $code, $is_json); | 
|     } | 
|   | 
|     /** | 
|      * 返回信息 | 
|      * @param  string  $content [description] | 
|      * @param  integer $code    [description] | 
|      * @param  boolean $is_json [description] | 
|      * @return [type]           [description] | 
|      */ | 
|     public function showMessage($content = '', $code = 200, $is_json = false){ | 
|       $return_msg = array('code' => $code, 'content' => $content); | 
|       if($is_json){ | 
|         $return_msg = json_encode($return_msg); | 
|       } | 
|       return $return_msg; | 
|     } | 
|   | 
|     /** | 
|      * 发送数据 | 
|      * @param  array   $arr     [description] | 
|      * @param  boolean $is_json [description] | 
|      * @return [type]           [description] | 
|      */ | 
|     public function send($arr = array(), $is_json = true){ | 
|       $return_data = $arr; | 
|       if($is_json){ | 
|         $return_data = json_encode($arr); | 
|       } | 
|       return $return_data; | 
|     } | 
|   | 
|     /** | 
|      * 向DataTable发送数据 | 
|      * @param  [type] $data [description] | 
|      * @return [type]       [description] | 
|      */ | 
|     public function sendToDataTable($data){ | 
|       return json_encode($data, JSON_UNESCAPED_UNICODE); | 
|     } | 
|   | 
|     /** | 
|      * 获取栏目列表 | 
|      * @return [type] [description] | 
|      */ | 
|     public function getModules(){ | 
|         $this->module_service = new Service_Module(); | 
|         return $this->module_service->getModuleList(array(), array(), array('level' => 1)); | 
|     } | 
|   | 
| } |