colly_wyx
2018-05-03 1237ba717c8e1902662747b94f7d302a6310cb8c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
//af_Loader::import('/core/BaseController');
/**
 * 后台通用控制器 加了rbac
 * Class AdminCommonController
 */
class System_Controller_Web extends System_Controller_Base{
 
    public $layout = APP_ROOT.'/modules/Admin/views/layout/adminLayout.phtml';
    public $defaultMsgTemplate = 'common/showmsg.phtml';
    public $config = array();
    /**
     * @var boolean 是否开启用户验证 authenticate
     */
    public $doAuth = true;
    /**
     * @var bool 是否检查权限
     */
    public $checkAuthorization = true;
 
    /**
     * @var string 当前请求的权限节点
     */
    public $currentRequest = '';
 
    public function init(){
        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);
    }
 
}