当前位置: 首页>>代码示例>>PHP>>正文


PHP Controller::beforeAction方法代码示例

本文整理汇总了PHP中Controller::beforeAction方法的典型用法代码示例。如果您正苦于以下问题:PHP Controller::beforeAction方法的具体用法?PHP Controller::beforeAction怎么用?PHP Controller::beforeAction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Controller的用法示例。


在下文中一共展示了Controller::beforeAction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: beforeAction

 public function beforeAction($action)
 {
     if (Yii::app()->user->isGuest) {
         $controller = Yii::app()->controller->getId();
         if ($controller != "default" || $action->getId() != 'login' && $action->getId() != 'index' && $action->getId() != 'captcha') {
             $this->redirect('/console/default/login');
         }
     } else {
         $userModel = CatalogUsers::fetch(Yii::app()->user->id);
         if (!$userModel || !$userModel->type_id) {
             Yii::app()->user->logout();
             $this->redirect('/console/default/login');
         }
         if ($userModel->type_id->id == 1) {
             $this->redirect('/');
         }
     }
     /*
             if ($this->getBackendUser()->getState('expires') > 0 && $this->getBackendUser()->getState('expires') < time()) {
                 $this->getBackendUser()->logout(false);
                 $this->redirect('/console');
             } else {
                 $this->checkAccess();
             }*/
     return parent::beforeAction($action);
 }
开发者ID:bogiesoft,项目名称:yii-travel,代码行数:26,代码来源:ConsoleController.php

示例2: beforeAction

 /**
  * Run before each action.
  *
  * @param CAction $action Passed action from Yii.
  *
  * @return boolean
  */
 public function beforeAction($action)
 {
     if ($action->Id == "checkout" && _xls_get_conf('ENABLE_SSL') == 1) {
         if (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on') {
             $this->redirect(Yii::app()->createAbsoluteUrl('cart/' . $action->Id, array(), 'https'));
             Yii::app()->end();
         }
     }
     // For passing a cart when not logged in under Common SSL
     if ($action->Id == "checkout" && Yii::app()->isCommonSSL && Yii::app()->user->isGuest) {
         $c = Yii::app()->getRequest()->getQuery('c');
         if (isset($c)) {
             $item = explode(",", _xls_decrypt($c));
             Yii::app()->shoppingcart->assign($item[0]);
         }
     }
     if (Yii::app()->shoppingcart->wasCartModified && Yii::app()->request->isAjaxRequest === false) {
         // Web Store has removed cart items or modified requested quantities
         // to reflect recent updates to inventory.
         // Since these changes may have invalidated the end user's originally selected shipping
         // option, clear cache of shipping info. When the user returns to checkout they will be
         // forced to recalculate shipping and choose from valid options
         Yii::app()->shoppingcart->clearCachedShipping();
         // Redirect the user to the index page and display the relevant message.
         $this->redirect(Yii::app()->createUrl('cart/index'));
     }
     return parent::beforeAction($action);
 }
开发者ID:uiDeveloper116,项目名称:webstore,代码行数:35,代码来源:CartController.php

示例3: beforeAction

 public function beforeAction($action)
 {
     if ($this->forceAjax) {
         $_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
     }
     return parent::beforeAction($action);
 }
开发者ID:niranjan2m,项目名称:Voyanga,代码行数:7,代码来源:BaseAjaxController.php

示例4: beforeAction

 protected function beforeAction($action)
 {
     //increase the max execution time
     @ini_set('max_execution_time', -1);
     //initial needed session variables
     $migrated_data = array('website_ids' => array(), 'store_group_ids' => array(), 'store_ids' => array(), 'category_ids' => array(), 'product_type_ids' => array(), 'product_ids' => array(), 'customer_group_ids' => array(), 'customer_ids' => array(), 'sales_object_ids' => array(), 'sales_order_ids' => array(), 'sales_quote_ids' => array(), 'sales_invoice_ids' => array(), 'sales_shipment_ids' => array(), 'sales_credit_ids' => array(), 'object_ids' => array(), 'review_ids' => array(), 'rating_ids' => array(), 'other_object_ids' => array());
     $migratedObj = (object) $migrated_data;
     //update migrated data
     $steps = MigrateSteps::model()->findAll("status = " . MigrateSteps::STATUS_DONE);
     if ($steps) {
         foreach ($steps as $step) {
             $migrated_data = json_decode($step->migrated_data);
             if ($migrated_data) {
                 $attributes = get_object_vars($migrated_data);
                 if ($attributes) {
                     foreach ($attributes as $attr => $value) {
                         $migratedObj->{$attr} = $value;
                     }
                 }
             }
         }
     }
     $attributes = get_object_vars($migratedObj);
     if ($attributes) {
         foreach ($attributes as $attr => $value) {
             Yii::app()->session['migrated_' . $attr] = $value;
         }
     }
     //end initial needed session variables
     return parent::beforeAction($action);
 }
开发者ID:korbax,项目名称:magento2_data_migration,代码行数:31,代码来源:MigrateController.php

示例5: beforeAction

 protected function beforeAction($action)
 {
     $reca = parent::beforeAction($action);
     return $reca;
     //check whether authenticated
     if (Yii::app()->request->isPostRequest) {
         //decode json
         try {
             $this->postData = json_decode(file_get_contents("php://input"));
         } catch (Exception $e) {
             throw new CHttpException(400, 'Bad request, invalid input format!');
         }
         //validate schema
         $validator = new JsonSchema\Validator();
         $validator->check($this->postData, ApiSchema::Schema(Yii::app()->controller->action->id));
         if (!$validator->isValid()) {
             $ret = '';
             foreach ($validator->getErrors() as $error) {
                 $ret .= '"' . $error['property'] . '" ' . $error['message'] . '<br />';
             }
             throw new CHttpException(401, 'Input data is invalid!');
         }
         //validate token
         if ($this->validateToken($this->postData->token)) {
             throw new CHttpException(402, 'Token is invalid!');
         }
     }
     return $reca;
 }
开发者ID:rubipikachu,项目名称:xoso-lechung,代码行数:29,代码来源:ApiController.php

示例6: beforeAction

 /**
  * A method that will be triggered before calling action method.
  * Any changes here will reflect then on Controller::triggerComponents() method
  *
  */
 public function beforeAction()
 {
     parent::beforeAction();
     $action = $this->request->param('action');
     $actions = ['getUsers', 'updateUserInfo', 'deleteUser'];
     // define the action methods that needs to be triggered only through POST & Ajax request.
     $this->Security->requireAjax($actions);
     $this->Security->requirePost($actions);
     // You need to explicitly define the form fields that you expect to be returned in POST request,
     // if form field wasn't defined, this will detected as form tampering attempt.
     switch ($action) {
         case "getUsers":
             $this->Security->config("form", ['fields' => ['name', 'email', 'role', 'page']]);
             break;
         case "updateUserInfo":
             $this->Security->config("form", ['fields' => ['user_id', 'name', 'password', 'role']]);
             break;
         case "deleteUser":
             $this->Security->config("form", ['fields' => ['user_id']]);
             break;
         case "updateBackup":
         case "restoreBackup":
             $this->Security->config("validateCsrfToken", true);
             break;
     }
 }
开发者ID:omarelgabry,项目名称:miniphp,代码行数:31,代码来源:AdminController.php

示例7: beforeAction

 protected function beforeAction($action)
 {
     if ($_SERVER['SERVER_NAME'] == "127.0.0.1" || $_SERVER['SERVER_NAME'] == "localhost") {
         Yii::app()->assetManager->forceCopy = true;
     }
     return parent::beforeAction($action);
 }
开发者ID:RomainLalande,项目名称:communecter,代码行数:7,代码来源:CommunecterController.php

示例8: beforeAction

 public function beforeAction($action)
 {
     if (Yii::app()->user->isGuest && $action->id != 'login') {
         $this->redirect(array('/users/userAdmin/login', 'redirect' => base64_encode($_SERVER['REQUEST_URI'])));
     }
     return parent::beforeAction($action);
 }
开发者ID:blindest,项目名称:Yii-CMS-2.0,代码行数:7,代码来源:AdminController.php

示例9: beforeAction

 public function beforeAction($action)
 {
     if (isset(Yii::app()->session['type'])) {
         Yii::app()->singly->setAccessToken(Yii::app()->session['token']);
     }
     return parent::beforeAction($action);
 }
开发者ID:ruXlab,项目名称:ontest,代码行数:7,代码来源:SiteController.php

示例10: beforeAction

 public function beforeAction()
 {
     //是否已经登录
     if (HSession::isLogin()) {
         $access_token_deadline = HSession::get('access_token_deadline', 0);
         if ($access_token_deadline > time()) {
             return parent::beforeAction();
         }
     }
     //获取code
     $code = $this->getParams('code', false);
     if ($code) {
         $user_data = WeiXin::model()->getUserWebAccessToken($code);
         $user_data['access_token_deadline'] = $user_data['expires_in'] + time();
         $user_info = WeiXin::model()->getSnsUserInfo($user_data['access_token'], $user_data['openid']);
         $user_data['nickname'] = isset($user_info['nickname']) ? $user_info['nickname'] : '';
         $user_data['sex'] = isset($user_info['sex']) ? $user_info['sex'] : '';
         $user_data['city'] = isset($user_info['city']) ? $user_info['city'] : '';
         $user_data['unionid'] = isset($user_info['unionid']) ? $user_info['unionid'] : '';
         HSession::login($user_data);
         return parent::beforeAction();
     }
     //跳转到微信auth2验证接口
     $url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
     $auth2url = WeiXin::model()->getAuth2Url($url);
     $this->redirect($auth2url);
 }
开发者ID:HWeiXin,项目名称:wx,代码行数:27,代码来源:IndexController.php

示例11: beforeAction

 public function beforeAction()
 {
     parent::beforeAction();
     $this->vars['globalPage'] = "newsfeed";
     $action = $this->request->param('action');
     $actions = ['getAll', 'create', 'getUpdateForm', 'update', 'getById', 'delete'];
     $this->Security->requireAjax($actions);
     $this->Security->requirePost($actions);
     switch ($action) {
         case "getAll":
             $this->Security->config("form", ['fields' => ['page_number']]);
             break;
         case "create":
             $this->Security->config("form", ['fields' => ['content']]);
             break;
         case "getUpdateForm":
             $this->Security->config("form", ['fields' => ['newsfeed_id']]);
             break;
         case "update":
             $this->Security->config("form", ['fields' => ['newsfeed_id', 'content']]);
             break;
         case "getById":
         case "delete":
             $this->Security->config("form", ['fields' => ['newsfeed_id']]);
             break;
     }
 }
开发者ID:E01T,项目名称:miniPHP,代码行数:27,代码来源:NewsFeedController.php

示例12: beforeAction

 public function beforeAction($action)
 {
     if (Yii::app()->user->isGuest) {
         $this->redirect('/wechat/help/nologin');
     }
     return parent::beforeAction($action);
 }
开发者ID:bfyang5130,项目名称:zzl,代码行数:7,代码来源:AbsWechatController.php

示例13: beforeAction

 public function beforeAction($action)
 {
     if (!$this->isSecureRequest()) {
         echo ':)';
         Yii::app()->end();
     }
     return parent::beforeAction($action);
 }
开发者ID:VanyaAvchyan,项目名称:Pol,代码行数:8,代码来源:ApiController.php

示例14: beforeAction

 /**
  * We want to ensure Wish lists are enabled before a user can view,
  * search and-or create lists. So, we display an exception to prevent
  *  running any of these processes.
  *
  * @param CAction $action
  * @return bool
  * @throws CHttpException
  */
 public function beforeAction($action)
 {
     if (_xls_get_conf('ENABLE_WISH_LIST', 0) == 0) {
         _xls_404('Wish lists are not enabled on this store.');
         return false;
     }
     return parent::beforeAction($action);
 }
开发者ID:uiDeveloper116,项目名称:webstore,代码行数:17,代码来源:WishlistController.php

示例15: beforeAction

 /**
  * Establecer como fondo de la pagina "bg-estadio-dentro"
  *
  * > Llamada a la funcion ```beforeAction```
  *
  * @param object $action
  * @return true
  */
 public function beforeAction($action)
 {
     if (!parent::beforeAction($action)) {
         return false;
     }
     Yii::app()->setParams(array('bgclass' => 'bg-estadio-dentro'));
     return true;
 }
开发者ID:rMarinf,项目名称:JugadorNum12,代码行数:16,代码来源:PartidosController.php


注:本文中的Controller::beforeAction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。