option(); Yii::app()->language = 'zh_cn'; $controller = Yii::app()->controller->id; $action = $this->getAction()->getId(); $path = strtolower($controller . '/'. $action); if(!in_array($path, LewaimaiAdminPingtaiAuth::$noLoginRouters) && Yii::app()->user->isGuest){ // Helper::error('请先登入1', 401); } if (!LewaimaiAdminPingtaiAuth::adminAuth($controller, $action) && (!Yii::app()->user->isGuest && Yii::app()->user->_id != 1)) { Helper::error('您没有相应的权限'); } return true; } /** * Redirects the browser to the specified URL or route (controller/action). * @param mixed $url the URL to be redirected to. If the parameter is an array, * the first element must be a route to a controller action and the rest * are GET parameters in name-value pairs. * @param boolean $terminate whether to terminate the current application after calling this method. Defaults to true. * @param integer $statusCode the HTTP status code. Defaults to 302. See {@link http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html} * for details about HTTP status code. */ public function redirect($url,$terminate=true,$statusCode=302) { if(is_array($url)) { $route=isset($url[0]) ? $url[0] : ''; $url=$this->createUrl($route,array_splice($url,1)); } header('Location: ' . $url, true, $statusCode); } public function jsonReturn($data) { echo CJSON::encode($data); } /** * 获取当前 page,用于列表跳转到其他页面后返回 * @return int * @author lizhi <1458705589@qq.com> * @date 2021/9/29 */ protected function getPage() { $c = Yii::app()->getRequest()->getCookies()->itemAt('return_page'); return $c ? $c->value : 1; } /** * 记录当前 page,用于列表跳转到其他页面后返回 * @author lizhi <1458705589@qq.com> * @date 2021/9/29 */ protected function setPage($name = 'page') { $page = Yii::app()->request->getParam($name, 1); Yii::app()->getRequest()->cookies['return_page'] = new CHttpCookie('return_page', $page, ['expire' => time() + 600]); } protected function response($data = []) { $arr = [ 'errcode' => 0, 'msg' => "ok", 'data' => $data ]; echo json_encode($arr); Yii::app()->end(); exit; } /* * 请求失败的时候返回 * $errcode 错误代码 * $errmsg 错误信息 */ protected function errorResponse($errcode, $errmsg = "") { // if ($errcode < 10001) { // $errcode = 99999; // } $arr = [ 'errcode' => $errcode, 'msg' => $errmsg, ]; echo json_encode($arr); Yii::app()->end(); exit; } }