/** * @inheritdoc */ public function behaviors() { return ['access' => ['class' => AccessControl::className(), 'only' => ['profile', 'return-to-edit', 'profile-to-pdf', 'spec-list', 'spec-items', 'agreement'], 'rules' => [['actions' => ['profile', 'return-to-edit', 'profile-to-pdf', 'spec-list', 'spec-items', 'agreement'], 'allow' => true, 'roles' => ['@']]]], 'verbs' => ['class' => VerbFilter::className(), 'actions' => ['return-to-edit' => ['post']]], ['class' => \yii\filters\HttpCache::className(), 'only' => ['view'], 'lastModified' => function ($action, $params) { $q = new \yii\db\Query(); return $q->from('profile')->max('updated_at'); }]]; }
/** * @inheritdoc */ public function behaviors() { $behaviors = ArrayHelper::merge(parent::behaviors(), ['authenticator' => ['class' => CompositeAuth::className(), 'authMethods' => [['class' => HttpBearerAuth::className()], ['class' => QueryParamAuth::className(), 'tokenParam' => 'accessToken']]], 'exceptionFilter' => ['class' => ErrorToExceptionFilter::className()], 'corsFilter' => ['class' => \backend\rest\filters\Cors::className(), 'cors' => ['Origin' => ['*'], 'Access-Control-Request-Method' => ['POST', 'PUT', 'OPTIONS', 'PATCH', 'DELETE'], 'Access-Control-Request-Headers' => ['X-Pagination-Total-Count', 'X-Pagination-Page-Count', 'X-Pagination-Current-Page', 'X-Pagination-Per-Page', 'Content-Length', 'Content-type', 'Link'], 'Access-Control-Allow-Credentials' => true, 'Access-Control-Max-Age' => 3600, 'Access-Control-Expose-Headers' => ['X-Pagination-Total-Count', 'X-Pagination-Page-Count', 'X-Pagination-Current-Page', 'X-Pagination-Per-Page', 'Content-Length', 'Content-type', 'Link'], 'Access-Control-Allow-Headers' => ['X-Pagination-Total-Count', 'X-Pagination-Page-Count', 'X-Pagination-Current-Page', 'X-Pagination-Per-Page', 'Content-Length', 'Content-type', 'Link']]]]); if (isset(\Yii::$app->params['httpCacheActive']) and \Yii::$app->params['httpCacheActive']) { $params = \Yii::$app->getRequest()->getQueryParams(); unset($params['accessToken']); $behaviors['httpCache'] = ['class' => HttpCache::className(), 'params' => $params, 'lastModified' => function ($action, $params) { $q = new \yii\db\Query(); $class = $this->modelClass; if (in_array('updated_at', $class::getTableSchema()->getColumnNames())) { return strtotime($q->from($class::tableName())->max('updated_at')); } if (in_array('modified', $class::getTableSchema()->getColumnNames())) { return strtotime($q->from($class::tableName())->max('modified')); } return null; }, 'etagSeed' => function (Action $action, $params) { $iterator = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($params)); $keys = array(); foreach ($iterator as $key => $value) { // Build long key name based on parent keys for ($i = $iterator->getDepth() - 1; $i >= 0; $i--) { $key = $iterator->getSubIterator($i)->key() . '_' . $key; if (!is_array($iterator->getSubIterator($i)->current())) { $value = $iterator->getSubIterator($i)->current() . '_' . $value; } } $keys[] = $key . '-' . $value; } $uniqueId = implode('-', $keys); return $uniqueId; }]; } return $behaviors; }
public function behaviors() { return ['httpCache' => ['class' => \yii\filters\HttpCache::className(), 'only' => ['index']]]; }