php yii-base-ActionFilter类(方法)实例源码

下面列出了php yii-base-ActionFilter 类(方法)源码代码实例,从而了解它的用法。

作者:manyoubaby12    项目:imsho   
/**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if ($this->view === null) {
         $this->view = Yii::$app->getView();
     }
 }

作者:nthrnt    项目:catering-termina   
public function beforeAction($action)
 {
     if (Yii::$app->request->isAjax) {
         return parent::beforeAction($action);
     }
     return $action->controller->redirect(['index']);
 }

作者:ivan-chk    项目:yii2-boos   
/**
  * @inheritdoc
  */
 public function beforeAction($action)
 {
     if (Yii::$app->getRequest()->getIsAjax()) {
         return parent::beforeAction($action);
     }
     throw new BadRequestHttpException('Bad Request. This url cannot handle a non-ajax request.');
 }

作者:121504837    项目:yii2-oauth2-rest-templat   
/**
  * @param Action $action
  * @return bool
  * @throws ForbiddenHttpException
  * @throws \yii\base\InvalidConfigException
  */
 public function beforeAction($action)
 {
     $action_name = $action->id;
     list($public_actions, $actions_scopes) = $this->analyzeAccessRules($action_name);
     if (in_array($action_name, $public_actions)) {
         //action is public
         return true;
     }
     // else, if not public, add additional auth filters
     if (Yii::$app->hasModule('oauth2')) {
         /** @var \filsh\yii2\oauth2server\Module $oauth_module */
         $oauth_module = Yii::$app->getModule('oauth2');
         $query_param_auth = ['class' => QueryParamAuth::className()];
         if (!empty($oauth_module->options['token_param_name'])) {
             $query_param_auth['tokenParam'] = $oauth_module->options['token_param_name'];
         }
         $auth_behavior = $this->owner->getBehavior('authenticator');
         $auth_behavior->authMethods = [$query_param_auth, ['class' => HttpBearerAuth::className()]];
         $scopes = isset($actions_scopes[$action_name]) ? $actions_scopes[$action_name] : '';
         if (is_array($scopes)) {
             $scopes = implode(' ', $scopes);
         }
         $oauthServer = $oauth_module->getServer();
         $oauthRequest = $oauth_module->getRequest();
         $oauthResponse = $oauth_module->getResponse();
         if (!$oauthServer->verifyResourceRequest($oauthRequest, $oauthResponse, $scopes)) {
             throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.'));
         }
     }
     return parent::beforeAction($action);
 }

作者:krisss    项目:YunDou-advance   
public function beforeAction($action)
 {
     if ($this->user['role'] >= Users::ROLE_OPERATION) {
         return parent::beforeAction($action);
     }
     throw new Exception("没有访问权限");
 }

作者:wangpengzhe    项目:we   
/**
  * 初始化方法
  */
 public function init()
 {
     parent::init();
     //获取user实例
     $this->user = Instance::ensure($this->user, User::className());
     $this->user_info = $this->user->identity;
 }

作者:radiata-cm    项目:radiat   
/**
  * @inheritdoc
  */
 public function beforeAction($action)
 {
     if (parent::beforeAction($action)) {
         $user = $this->getUser();
         if (in_array($action->getUniqueId(), $this->allowedActions)) {
             return true;
         } elseif ($user->isGuest) {
             Yii::$app->response->redirect(['/radiata/login'])->send();
             return false;
         } elseif (in_array($action->getUniqueId(), $this->allowedActionsLoggedIn)) {
             return true;
         }
         $userGroups = Yii::$app->authManager->getAssignments($user->id);
         if (self::checkFullAccess()) {
             return true;
         } elseif (isset($userGroups['manager'])) {
             if ($action->controller->id == 'radiata' && isset($userGroups['manager'])) {
                 return true;
             } elseif (defined(get_class($action->controller) . '::BACKEND_PERMISSION') && $user->can(constant(get_class($action->controller) . '::BACKEND_PERMISSION'))) {
                 return true;
             } elseif (!defined(get_class($action->controller) . '::BACKEND_PERMISSION') && defined(get_class($action->controller->module) . '::BACKEND_PERMISSION') && $user->can(constant(get_class($action->controller->module) . '::BACKEND_PERMISSION'))) {
                 return true;
             } else {
                 throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.'));
             }
         } else {
             throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.'));
         }
     }
     return false;
 }

作者:heartshar    项目:yii2-cha   
public function beforeAction($action)
 {
     if (\Yii::$app->request->isAjax) {
         return parent::beforeAction($action);
     }
     throw new BadRequestHttpException();
 }

作者:czechcamu    项目:daspor   
/**
  * @param \yii\base\Action $action
  *
  * @return bool
  * @throws InvalidParamException
  */
 public function beforeAction($action)
 {
     $session = \Yii::$app->session;
     $request = \Yii::$app->request;
     if ($request->post('web_id')) {
         $id = $request->post('web_id');
         $session->set('web_id', $id);
     } elseif ($session->get('web_id')) {
         $web = WebRecord::findOne($session->get('web_id'));
         if ($web) {
             $id = $session->get('web_id');
         } else {
             $id = WebRecord::getMainWebId();
             $session->set('web_id', $id);
         }
     } else {
         $id = WebRecord::getMainWebId();
         $session->set('web_id', $id);
     }
     $session->close();
     /** @var $controller MenuController */
     $controller = $this->owner;
     $controller->setWeb($id);
     return parent::beforeAction($action);
 }

作者:kissara    项目:yii2-templat   
public function beforeAction($action)
 {
     if (in_array(Yii::$app->controller->action->id, $this->only)) {
         Yii::$app->controller->enableCsrfValidation = false;
     }
     return parent::beforeAction($action);
 }

作者:Jasmine    项目:yii2-rest-wal   
public function init()
 {
     parent::init();
     if ($this->allowActions && $this->denyActions) {
         throw new \yii\base\InvalidConfigException("allowActions and denyActions only one can be set");
     }
 }

作者:czechcamu    项目:daspor   
/**
  * @param \yii\base\Action $action
  *
  * @return bool
  * @throws InvalidParamException
  */
 public function beforeAction($action)
 {
     $session = \Yii::$app->session;
     $request = \Yii::$app->request;
     if ($request->post('web_id')) {
         $session->set('web_id', $request->post('web_id'));
         $id = MenuRecord::getMainMenuId();
         $session->set('menu_id', $id);
     } else {
         if ($request->post('menu_id')) {
             $id = $request->post('menu_id');
             $session->set('menu_id', $id);
         } elseif ($session->get('menu_id')) {
             $menu = MenuRecord::findOne($session->get('menu_id'));
             if ($menu) {
                 $id = $session->get('menu_id');
             } else {
                 $id = MenuRecord::getMainMenuId();
                 $session->set('menu_id', $id);
             }
         } else {
             $id = MenuRecord::getMainMenuId();
             $session->set('menu_id', $id);
         }
     }
     $session->close();
     /* @var $controller \backend\controllers\MenuItemController */
     $controller = $this->owner;
     $controller->setMenu($id);
     return parent::beforeAction($action);
 }

作者:vsgut    项目:cr   
public function afterAction($action, $result)
 {
     $res = parent::afterAction($action, $result);
     if ($this->ajaxMode) {
         if ($res) {
             $dom = Yii::createObject(['class' => Dom::className(), 'html' => $res]);
             if (!empty($_REQUEST['target_id'])) {
                 $target_id = explode(',', $_REQUEST['target_id']);
                 $this->ajaxVars['html'] = $dom->getElementByIds($target_id);
             }
             list($scripts, $src) = $dom->getScripts();
             if ($scripts) {
                 $this->ajaxVars['scripts'] = $scripts;
             }
             if ($src && 0) {
                 // disabled
                 $this->ajaxVars['scripts_src'] = $src;
             }
         }
         // Flashes
         if (!isset($this->ajaxVars['alerts'])) {
             $this->ajaxVars['alerts'] = Yii::$app->session->getAllFlashes();
         }
         Yii::$app->response->format = 'json';
         return $this->ajaxVars;
     }
     return $res;
 }

作者:krisss    项目:YunDou-advance   
public function beforeAction($action)
 {
     $session = Yii::$app->session;
     $user = $session->get('user');
     if (!TestLibrary::checkIsExist($user)) {
         $url = Url::to(['site/test-library-not-found']);
         header("Location:{$url}");
     }
     $practiceRecordFlag = $session->getFlash('practiceRecordFlag');
     if ($practiceRecordFlag) {
         //支付方案如果已经生成直接显示过去
         return parent::beforeAction($action);
     }
     $practiceRecord = PracticeRecord::findByUser($user['userId']);
     if (!$practiceRecord) {
         //如果没有练习权
         //获取在线练习支付方案
         /** @var $scheme \common\models\Scheme */
         $schemes = Scheme::findPracticeScheme();
         $session->setFlash('practice-schemes', $schemes);
         //存入session,在练习首页使用
         $session->setFlash('practiceRecordFlag', true);
         //支付方案生成的标志
         $url = Url::to(['practice/index', true]);
         header("Location:{$url}");
         return false;
     }
     return parent::beforeAction($action);
 }

作者:nthrnt    项目:catering-termina   
public function beforeAction($action)
 {
     if (!in_array($this->getClientIp(), Yii::$app->params['terminalAllowedIps'])) {
         throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.'));
     }
     return parent::beforeAction($action);
 }

作者:reuhtt    项目:yii2-admi   
public function beforeAction($action)
 {
     if (Yii::$app->user->identity->changePasswordRequired() || Yii::$app->user->identity->temp_pswd_flag) {
         Yii::$app->getSession()->setFlash('success', Yii::t('app', 'You must change your password before you can proceed.'));
         Yii::$app->controller->redirect(['/admin/sys-user/change-my-password']);
     }
     return parent::beforeAction($action);
 }

作者:rajanishtime    项目:basicyi   
/**
  * Initializes the [[rules]] array by instantiating rule objects from configurations.
  */
 public function init()
 {
     parent::init();
     $this->user = Instance::ensure($this->user, User::className());
     if ($this->user->identity !== null) {
         $this->user->identity->getRules();
     }
 }

作者:HEXA-U    项目:supervisor-manage   
/**
  * @param ActionEvent $event
  * @return boolean
  * @throws MethodNotAllowedHttpException when the request method is not allowed.
  */
 public function beforeAction($event)
 {
     if (Yii::$app->request->isAjax) {
         return parent::beforeAction($event);
     } else {
         $this->denyAccess(Yii::$app->user);
     }
 }

作者:krisss    项目:YunDou-advance   
public function beforeAction($action)
 {
     if ($this->user['role'] == Users::ROLE_AA || $this->user['role'] == Users::ROLE_AAA) {
         return parent::beforeAction($action);
     }
     Yii::$app->getResponse()->redirect(Url::to(['/site/index']));
     return false;
 }

作者:czechcamu    项目:daspor   
/**
  * @param \yii\base\Action $action
  *
  * @return bool
  * @throws InvalidParamException
  */
 public function beforeAction($action)
 {
     $model = new FileRecord();
     $images = $model->synchronizeImages();
     $files = $model->synchronizeFiles();
     $model->checkDB(array_merge($images, $files));
     return parent::beforeAction($action);
 }


问题


面经


文章

微信
公众号

扫码关注公众号