The class of the ActiveRecord should be specified via [[modelClass]], which must implement ActiveRecordInterface.
By default, the following actions are supported:
- index: list of models
- view: return the details of a model
- create: create a new model
- update: update an existing model
- delete: delete an existing model
- options: return the allowed HTTP methods
You may disable some of these actions by overriding ActiveController::actions and unsetting the corresponding actions.
To add a new action, either override ActiveController::actions by appending a new action class or write a new action method.
Make sure you also override ActiveController::verbs to properly declare what HTTP methods are allowed by the new action.
You should usually override ActiveController::checkAccess to check whether the current user has the privilege to perform
the specified action against the specified model.
public function actions() { $actions = parent::actions(); // personalizza il data provider preparation con il metodo "prepareDataProvider()" $actions['index']['prepareDataProvider'] = [$this, 'prepareDataProvider']; return $actions; }
public function behaviors() { $behaviors = parent::behaviors(); $behaviors['authenticator']['class'] = QueryParamAuth::className(); $behaviors['authenticator']['tokenParam'] = 'access_token'; return $behaviors; }
public function actions() { $actions = parent::actions(); $actions['index']['prepareDataProvider'] = [$this, 'prepareDataProvider']; //$actions['create']['run'] = [$this, 'run1']; return $actions; }
public function behaviors() { $behaviors = parent::behaviors(); $behaviors['authenticator'] = ['class' => HttpBearerAuth::className(), 'except' => ['options']]; $behaviors['corsFilter'] = ['class' => Cors::className()]; return $behaviors; }
public function actions() { $actions = parent::actions(); unset($actions['index']); unset($actions['view']); return $actions; }
public function behaviors() { $behaviors = parent::behaviors(); $behaviors['authenticator'] = ['class' => HttpBearerAuth::className()]; $behaviors['contentNegotiator'] = ['class' => ContentNegotiator::className(), 'formats' => ['application/json' => Response::FORMAT_JSON]]; return $behaviors; }
public function behaviors() { $behaviors = parent::behaviors(); $behaviors['authenticator'] = ['class' => CompositeAuth::className(), 'except' => ['login', 'error'], 'authMethods' => [HttpBearerAuth::className()]]; unset($behaviors['rateLimiter']); return $behaviors; }
/** * @inheritdoc */ public function behaviors() { $behaviors = parent::behaviors(); $behaviors['rateLimiter'] = ['class' => RateLimiter::className(), 'enableRateLimitHeaders' => false]; $behaviors['contentNegotiator'] = ['class' => ContentNegotiator::className(), 'formats' => ['application/json' => Response::FORMAT_JSON]]; return $behaviors; }
public function behaviors() { $behaviors = parent::behaviors(); //$behaviors['contentNegotiator']['formats']['text/html'] = Response::FORMAT_JSON; //setting JSON as default reply $behaviors['authenticator'] = ['class' => CompositeAuth::className(), 'authMethods' => [HttpBasicAuth::className(), HttpBearerAuth::className(), QueryParamAuth::className()]]; return $behaviors; }
public function behaviors() { $behaviors = parent::behaviors(); /* // test with basic auth which can be set in params $behaviors['authenticator'] = [ 'class' => HttpBasicAuth::className(), 'auth' => function ($username, $password) { if ($username==\Yii::$app->params['HttpBasicAuth']['username'] && $password==\Yii::$app->params['HttpBasicAuth']['password']) { return new User(); } else { return null; } }]; */ $behaviors['authenticator'] = ['class' => CompositeAuth::className(), 'authMethods' => [HttpBasicAuth::className(), QueryParamAuth::className()]]; /* //set response header to application/json only $behaviors['contentNegotiator'] = [ 'class' => ContentNegotiator::className(), 'formats' => [ 'application/json' => Response::FORMAT_JSON, // 'application/xml' => Response::FORMAT_XML, ], ]; */ return $behaviors; }
public function actions() { $actions = parent::actions(); unset($actions['index'], $actions['update'], $actions['create'], $actions['delete'], $actions['view']); //unset($actions['update'], $actions['create'], $actions['delete'], $actions['view']); return $actions; }
public function actions() { $actions = parent::actions(); // customize the data provider preparation with the "prepareDataProvider()" method $actions['index']['prepareDataProvider'] = [$this, 'prepareDataProvider']; return $actions; }
public function behaviors() { $self = self::className(); $behaviors = parent::behaviors(); $behaviors['access'] = ['class' => \app\components\filters\AccessControl::className(), 'rules' => $self::getAccessRules()]; return $behaviors; }
public function behaviors() { $behaviors = parent::behaviors(); $behaviors['verbs'] = ['class' => VerbFilter::className(), 'actions' => ['indexWithQuote' => ['get']]]; $behaviors['authenticator'] = ['class' => HttpBasicAuth::className()]; return $behaviors; }
public function behaviors() { $behaviors = parent::behaviors(); // enabled HttpBearerAuth $behaviors['authenticator'] = ['class' => HttpBearerAuth::className()]; return $behaviors; }
/** * Override the base actions in order to support some enhancements of actions * by default for all active controllers. * @see \yii\rest\ActiveController::actions() */ public function actions() { $actions = parent::actions(); $actions['index']['class'] = '\\luya\\rest\\actions\\IndexAction'; $actions['delete']['class'] = '\\luya\\rest\\actions\\DeleteAction'; return $actions; }
/** * Some rules in this controller * @return Rules behaviors */ public function behaviors() { $behaviors = parent::behaviors(); $behaviors['authenticator'] = ['class' => QueryParamAuth::className(), 'tokenParam' => 'token']; unset($behaviors['rateLimiter']); return $behaviors; }
public function actions() { $actions = parent::actions(); // remove parent's control over create unset($actions['create']); return $actions; }
public function actions() { $actions = parent::actions(); unset($actions['view']); $actions1 = ArrayHelper::merge(['actionPedido'], $actions); return $actions1; }
/** * 行为扩展 * @return array */ public function behaviors() { $behaviors = parent::behaviors(); // $behaviors['contentNegotiator']['formats']['text/html'] = Response::FORMAT_HTML; $behaviors['contentNegotiator']['formats'] = ['application/json' => Response::FORMAT_JSON]; return $behaviors; }
public function actions() { $actions = parent::actions(); // disable the "delete" and "create" actions unset($actions['delete'], $actions['create']); return $actions; }
public function behaviors() { $behaviors = parent::behaviors(); // $behaviors['authenticator'] = [ // 'class' => HttpBasicAuth::className(), // ]; return $behaviors; }
/** * @inheritdoc */ public function behaviors() { // send Authorization : Basic base64(token:) in header $behaviors = parent::behaviors(); $behaviors['authenticator'] = ['class' => HttpBasicAuth::className()]; $behaviors['verbs'] = ['class' => VerbFilter::className(), 'actions' => ['index' => ['GET'], 'view' => ['GET'], 'create' => ['PUT'], 'update' => ['POST', 'PATCH'], 'delete' => ['DELETE']]]; return $behaviors; }
public function actions() { $actions = parent::actions(); // change index class $actions['index']['class'] = '\\admin\\rest\\IndexAction'; $actions['delete']['class'] = '\\admin\\rest\\DeleteAction'; return $actions; }
/** * Переобределяем свои действия * @return array */ public function actions() { $actions = parent::actions(); unset($actions['index']); //unset($actions['update']); $this->model = new $this->modelClass(); return $actions; }
public function _checkAccess($action, $model = null, $params = array()) { var_dump($action); var_dump($model); var_dump($params); die; parent::checkAccess($action, $model, $params); }
public function beforeAction($action) { if (!parent::beforeAction($action)) { return false; } Yii::$app->response->format = Response::FORMAT_JSON; return true; }
/** * @inheritdoc */ public function afterAction($action, $result) { $result = parent::afterAction($action, $result); $result = $this->serializeData($result); if (!isset($result['code'])) { return ApiHelper::successResponse($result); } return $result; }
/** * @return array */ public function behaviors() { $behaviors = parent::behaviors(); $behaviors['authenticator'] = ['class' => CompositeAuth::className(), 'authMethods' => [['class' => HttpBasicAuth::className(), 'auth' => function ($username, $password) { $user = User::findByLogin($username); return $user->validatePassword($password) ? $user : null; }], HttpBearerAuth::className(), QueryParamAuth::className()]]; return $behaviors; }
/** * @inheritdoc */ public function behaviors() { $behaviors = parent::behaviors(); $behaviors['authenticator'] = ['class' => HttpBearerAuth::className(), 'only' => ['dashboard']]; $behaviors['access'] = ['class' => AccessControl::className(), 'only' => ['dashboard'], 'rules' => [['actions' => ['dashboard'], 'allow' => true, 'roles' => ['@']]]]; return $behaviors; }