Action provides a way to reuse action method code. An action method in an Action class can be used in multiple controllers or in different projects. Derived classes must implement a method named run(). This method will be invoked by the controller when the action is requested. The run() method can have parameters which will be filled up with user input values automatically according to their names. For example, if the run() method is declared as follows: php public function run($id, $type = 'book') { ... } And the parameters provided for the action are: ['id' => 1]. Then the run() method will be invoked as run(1) automatically. For more details and usage information on Action, see the guide article on actions.
Since: 2.0
Author: Qiang Xue (qiang.xue@gmail.com)
Inheritance: extends Component
Exemplo n.º 1
28
 public function init()
 {
     //csrf状态
     Yii::$app->request->enableCsrfValidation = $this->csrf;
     Yii::$app->request->enableCookieValidation = $this->csrf;
     //当前目录
     $this->currentPath = dirname(__FILE__);
     return parent::init();
 }
Exemplo n.º 2
1
 /**
  * Returns description for method
  * @return string
  */
 public function description()
 {
     if (method_exists($this->action, 'description')) {
         return $this->action->description();
     }
     return $this->docBlock ? $this->docBlock->getShortDescription() : '';
 }
Exemplo n.º 3
0
 /**
  * Returns a value indicating whether the filer is active for the given action.
  * @param \yii\base\Action $action the action being filtered
  * @return boolean whether the filer is active for the given action.
  */
 protected function isActive($action)
 {
     if ($action->getUniqueId() === Yii::$app->getErrorHandler()->errorAction) {
         return false;
     }
     return parent::isActive($action);
 }
Exemplo n.º 4
0
 /**
  * check the permission, if we rewrite and controller, the controller id and module id is not changed
  * @param \yii\base\Action $action
  * @param \yii\web\User $user
  * @param \yii\web\Request $request
  * @return bool
  */
 public function matchActionAccess($action, $user, $request)
 {
     if ($user->getIsGuest()) {
         return false;
     }
     /** @var \core\auth\Module $authModule */
     $authModule = \Yii::$app->getModule('core_auth');
     foreach ($authModule->getAdmins() as $key => $admin) {
         if ($user->getIdentity()->username == $admin['username']) {
             return true;
         }
     }
     if ($action->controller->module instanceof Application) {
         $key = 'default' . '_' . $action->controller->id . '_' . $action->id;
     } else {
         $key = $action->getUniqueId();
         $key = explode('/', $key);
         array_shift($key);
         $key = implode('_', $key);
     }
     $key = lcfirst(implode('', array_map(function ($k) {
         return ucfirst($k);
     }, explode('-', $key))));
     return $user->can($key, $this->params);
 }
Exemplo n.º 5
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if (!empty($this->data)) {
         $this->data = call_user_func($this->data);
     }
 }
Exemplo n.º 6
0
 public function init()
 {
     parent::init();
     if (!$this->model) {
         throw new InvalidParamException('model不能为null');
     }
 }
Exemplo n.º 7
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if (empty($this->callable)) {
         throw new InvalidParamException('Param "callable" can not be empty.');
     }
 }
Exemplo n.º 8
0
 public function init()
 {
     //close csrf
     Yii::$app->request->enableCsrfValidation = false;
     //默认设置
     // $this->php_path =  dirname(__FILE__) . '/';
     $this->php_path = $_SERVER['DOCUMENT_ROOT'] . '/';
     $this->php_url = '/';
     //根目录路径,可以指定绝对路径,比如 /var/www/attached/
     $this->root_path = $this->php_path . 'upload/';
     //根目录URL,可以指定绝对路径,比如 http://www.yoursite.com/attached/
     $this->root_url = $this->php_url . 'upload/';
     //图片扩展名
     //            $ext_arr = ['gif', 'jpg', 'jpeg', 'png', 'bmp'],
     //文件保存目录路径
     $this->save_path = $this->php_path . 'upload/';
     //文件保存目录URL
     $this->save_url = $this->php_url . 'upload/';
     //定义允许上传的文件扩展名
     //            $ext_arr = array(
     //                'image' => array('gif', 'jpg', 'jpeg', 'png', 'bmp'),
     //                'flash' => array('swf', 'flv'),
     //                'media' => array('swf', 'flv', 'mp3', 'wav', 'wma', 'wmv', 'mid', 'avi', 'mpg', 'asf', 'rm', 'rmvb'),
     //                'file' => array('doc', 'docx', 'xls', 'xlsx', 'ppt', 'htm', 'html', 'txt', 'zip', 'rar', 'gz', 'bz2'),
     //            ),
     //最大文件大小
     $this->max_size = 1000000;
     $this->save_path = realpath($this->save_path) . '/';
     //load config file
     parent::init();
 }
 /**
  * @throws InvalidConfigException
  */
 public function init()
 {
     parent::init();
     if (!is_callable($this->outputFunction)) {
         throw new InvalidConfigException('outputFunction must be callable');
     }
 }
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if (empty($this->modelClass)) {
         throw new InvalidConfigException('The "modelClass" property must be set.');
     }
 }
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if ($this->modelClass == null) {
         throw new InvalidConfigException('Param "modelClass" must be contain model name with namespace.');
     }
 }
 /**
  * @inheritdoc
  * @throws InvalidConfigException
  */
 public function init()
 {
     if (!isset($this->ownerLinkTable, $this->className)) {
         throw new InvalidConfigException('"ownerLinkTable" and "className" attributes cannot be null');
     }
     parent::init();
 }
Exemplo n.º 13
0
 /**
  * @inheritdoc
  * @throws \yii\base\InvalidConfigException
  */
 public function init()
 {
     if ($this->modelClass === null) {
         throw new InvalidConfigException('"modelClass" cannot be empty.');
     }
     parent::init();
 }
 /**
  * @inheritdoc
  * @throws InvalidConfigException
  */
 public function init()
 {
     if (!isset($this->ownerRelation, $this->ownerTable, $this->searchClass, $this->view)) {
         throw new InvalidConfigException('"searchClass", "ownerRelation", "ownerTable" and "view" attributes cannot be null');
     }
     parent::init();
 }
Exemplo n.º 15
0
 /**
  * @return bool
  */
 public function beforeRun()
 {
     Yii::$app->view->title = 'Update Record';
     Yii::$app->view->params['breadcrumbs'][] = ['label' => 'Review Errors', 'url' => ['review-errors', 'id' => Yii::$app->request->get('id')]];
     Yii::$app->view->params['breadcrumbs'][] = Yii::$app->view->title;
     return parent::beforeRun();
 }
Exemplo n.º 16
0
 protected function afterRun()
 {
     if (is_callable($this->afterRun)) {
         return call_user_func($this->afterRun);
     }
     parent::afterRun();
 }
Exemplo n.º 17
0
 /**
  * Check if action has valid findModel method
  */
 public function init()
 {
     parent::init();
     if (!is_callable($this->findModel)) {
         throw new InvalidConfigException('findModel must be set');
     }
 }
Exemplo n.º 18
0
 public function init()
 {
     parent::init();
     foreach ($this->allowedRoutes as &$allowedRoute) {
         $allowedRoute = ltrim(Yii::getAlias($allowedRoute), '/');
     }
     return $this->controller->redirect(Yii::$app->request->getReferrer());
 }
Exemplo n.º 19
0
 public function init()
 {
     parent::init();
     $this->controller->enableCsrfValidation = false;
     Yii::$app->response->setStatusCode(200);
     Yii::$app->response->format = \yii\web\Response::FORMAT_RAW;
     Yii::$app->response->headers->set('Content-Type', 'application/xml; charset=utf-8');
 }
Exemplo n.º 20
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     $this->api = \Yii::$app->get($this->componentName);
     if (!$this->api instanceof Api) {
         throw new InvalidConfigException('Invalid PerfectMoney component configuration');
     }
     parent::init();
 }
Exemplo n.º 21
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if (!empty($this->defaultValues)) {
         $this->defaultValues = call_user_func($this->defaultValues);
         $this->assignDefaultValues();
     }
 }
Exemplo n.º 22
0
 public function init()
 {
     $this->currentPath = dirname(__FILE__);
     Yii::$app->request->enableCsrfValidation = false;
     Yii::$app->request->enableCookieValidation = true;
     $this->config = array_merge(['uploadDir' => date('Y/m/d'), 'webroot' => Yii::getAlias('@webroot')], $this->config);
     parent::init();
 }
Exemplo n.º 23
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     $this->targetDirectory = Yii::getAlias($this->targetDirectory);
     if (is_callable($this->fileName)) {
         $this->fileName = call_user_func($this->fileName, $this);
     }
 }
Exemplo n.º 24
0
 /**
  * @inheritdoc
  * @throws InvalidConfigException
  */
 public function init()
 {
     parent::init();
     if (empty($this->gridId) || empty($this->gridManager)) {
         throw new InvalidConfigException('Property "gridId" and "gridManager" must be specified.');
     }
     $this->gridManager = Instance::ensure($this->gridManager, 'bupy7\\grid\\interfaces\\ManagerInterface');
 }
Exemplo n.º 25
0
 public function init()
 {
     //close csrf
     Yii::$app->request->enableCsrfValidation = false;
     Yii::$app->response->format = Response::FORMAT_JSON;
     $this->driver = Yii::$app->request->get('driver', 'local');
     parent::init();
 }
Exemplo n.º 26
0
 /**
  * Disabling CSRF validation
  */
 public function init()
 {
     Yii::$app->request->enableCsrfValidation = false;
     if (!is_array($this->sizeList)) {
         throw new Exception("Please, set sizeList array!");
     }
     parent::init();
 }
Exemplo n.º 27
0
 public function init()
 {
     //close csrf
     Yii::$app->request->enableCsrfValidation = false;
     //默认设置
     $_config = (require __DIR__ . '/config.php');
     $this->config = ArrayHelper::merge($_config, $this->config);
     parent::init();
 }
 public function init()
 {
     include_once dirname(__FILE__) . '/OssManager.php';
     Yii::$app->request->enableCsrfValidation = false;
     Yii::$app->request->enableCookieValidation = true;
     $this->config = array_merge(['uploadDir' => date('Y/m/d'), 'webroot' => Yii::getAlias('@webroot')], $this->config);
     $this->oss_article = new OssManager($this->config['bucket'], $this->config['access_id'], $this->config['access_key'], $this->config['end_point']);
     parent::init();
 }
Exemplo n.º 29
0
 /**
  * Initializes the action and ensures the temp path exists.
  */
 public function init()
 {
     parent::init();
     Yii::$app->response->format = Response::FORMAT_JSON;
     $this->tempPath = Yii::getAlias($this->tempPath);
     if (!is_dir($this->tempPath)) {
         FileHelper::createDirectory($this->tempPath, $this->dirMode, true);
     }
 }
Exemplo n.º 30
-1
 public function init()
 {
     parent::init();
     Yii::$app->request->enableCsrfValidation = false;
     $_config = (require __DIR__ . '/config.php');
     $this->config = ArrayHelper::merge($_config, $this->config);
     //        print_r($this->config);die;
 }