本文整理汇总了PHP中yii\rest\ActiveController::beforeAction方法的典型用法代码示例。如果您正苦于以下问题:PHP ActiveController::beforeAction方法的具体用法?PHP ActiveController::beforeAction怎么用?PHP ActiveController::beforeAction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\rest\ActiveController
的用法示例。
在下文中一共展示了ActiveController::beforeAction方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: beforeAction
public function beforeAction($action)
{
if (!parent::beforeAction($action)) {
return false;
}
Yii::$app->response->format = Response::FORMAT_JSON;
return true;
}
示例2: beforeAction
/**
* This method is used to valide the user's authority with token.
* This method is invoked right before an action is executed.
*
* The method will trigger the [[EVENT_BEFORE_ACTION]] event. The return value of the method
* will determine whether the action should continue to run.
*
* If you override this method, your code should look like the following:
*
* ```php
* public function beforeAction($action)
* {
* if (parent::beforeAction($action)) {
* // your custom code here
* return true; // or false if needed
* } else {
* return false;
* }
* }
* ```
*
* @param Action $action the action to be executed.
* @return boolean whether the action should continue to run.
* @author Harry Sun
*/
public function beforeAction($action)
{
if (parent::beforeAction($action)) {
$this->attachBehavior('ControllerBehavior', new ControllerBehavior());
$token = $this->getAccessToken();
return $this->checkAuth($this->module, $token);
}
throw new HttpException(400, "Fail to resolve the action.");
}
示例3: beforeAction
public function beforeAction($action)
{
if (!parent::beforeAction($action)) {
return false;
}
return $this->encryptDataBeforeAction();
// your custom code here
//return true; // or false to not run the action
}
示例4: beforeAction
/**
* @param \yii\base\Action $action
* @return bool
* @throws \yii\web\BadRequestHttpException
*/
public function beforeAction($action)
{
if (parent::beforeAction($action)) {
$this->request = Yii::$app->request;
Yii::info('请求地址:' . $this->request->absoluteUrl, 'request');
Yii::info('请求数据:' . $this->request->rawBody, 'request');
return true;
} else {
return false;
}
}
示例5: beforeAction
public function beforeAction($action)
{
if (!parent::beforeAction($action)) {
return false;
}
foreach ($this->validateNested as $action) {
if ($this->action->id === $action) {
if ($this->indexDataProvider()->getTotalCount() === 0) {
throw new NotFoundHttpException("Object not found");
}
}
}
return true;
}
示例6: beforeAction
/**
* @param \yii\base\Action $event
* @return bool
*/
public function beforeAction($event)
{
try {
$valid = parent::beforeAction($event);
if ($valid && in_array($event->id, ['create']) && !preg_match('~' . Response::FORMAT_JSON . '~', Yii::$app->request->contentType)) {
$this->showError(406, "Content type must be '" . Response::FORMAT_JSON . "'");
return false;
}
if ($valid && in_array($event->id, ['update', 'delete'])) {
$this->showError(403, "Access denied to action '" . $event->id . "'");
return false;
}
return $valid;
} catch (Exception $e) {
$this->showError(405, $e->getMessage());
return false;
}
}
示例7: beforeAction
public function beforeAction($action)
{
$request = Yii::$app->request;
$paras = $request->isPost ? $request->post() : $request->get();
if (!isset($paras['access_token'])) {
Yii::$app->getResponse()->content = array('token_status' => -1, 'last_login' => '');
return parent::beforeAction($action);
}
$user1 = \app\models\User::find()->where(['access_token' => $paras['access_token']])->one();
$user2 = \app\models\User::find()->where(['old_token' => $paras['access_token']])->one();
$token_status = 0;
$last_login = null;
if (!is_null($user1)) {
$last_login = $user1->last_login;
$token_status = 1;
}
if (!is_null($user2)) {
$last_login = $user2->last_login;
$token_status = 2;
}
Yii::$app->getResponse()->content = array('token_status' => $token_status, 'last_login' => $last_login);
//Yii::$app->getResponse()->send();
return parent::beforeAction($action);
}
示例8: beforeAction
/**
* @inheritdoc
*/
public function beforeAction($action)
{
/** @var ContentNegotiator $negotiator */
if (($negotiator = $this->getBehavior('contentNegotiator')) !== null) {
$negotiator->negotiate();
if (Yii::$app->response->format !== Response::FORMAT_HTML) {
$this->enableCsrfValidation = false;
}
}
return parent::beforeAction($action);
}
示例9: beforeAction
public function beforeAction($action)
{
$this->enableCsrfValidation = false;
return parent::beforeAction($action);
}
示例10: beforeAction
public function beforeAction($event)
{
return parent::beforeAction($event);
}
示例11: beforeAction
public function beforeAction($action)
{
$this->page_size = Yii::$app->request->get('per-page') ? Yii::$app->request->get('per-page') : $this->page_size;
if ($action->id == 'create' || $action->id == 'update') {
if ($this->auto_filter_user && $this->user_identifier_column) {
$params = Yii::$app->getRequest()->getBodyParams();
$params[$this->user_identifier_column] = strval(Yii::$app->user->id);
Yii::$app->getRequest()->setBodyParams($params);
}
}
return $this->handleBeforeActionEvent($action) && parent::beforeAction($action);
}