public function beforeAction($action) { if (Yii::$app->user->isGuest) { Yii::$app->getResponse()->redirect(\Yii::$app->getUser()->loginUrl)->send(); } return parent::beforeAction($action); }
/** * 后台所有的行为都要进行登录才能操作 */ function beforeAction($action) { if (!parent::beforeAction($action)) { return false; } if (\Yii::$app->user->isGuest) { return $this->goHome(); } return true; }
public function init() { parent::init(); Yii::$app->set('authClientCollection', ['class' => 'yii\\authclient\\Collection', 'clients' => ['google' => ['class' => 'yii\\authclient\\clients\\GoogleOAuth', 'clientId' => Yii::$app->setting->get('googleClientId'), 'clientSecret' => Yii::$app->setting->get('googleClientSecret')], 'github' => ['class' => 'yii\\authclient\\clients\\GitHub', 'clientId' => Yii::$app->setting->get('githubClientId'), 'clientSecret' => Yii::$app->setting->get('githubClientSecret')]]]); }
public function behaviors() { return ArrayHelper::merge(parent::behaviors(), ['contentNegotiator' => ['class' => ContentNegotiator::className(), 'formats' => ['application/json' => Response::FORMAT_JSON], 'only' => ['add-to-cart', 'change-quantity', 'delete']]]); }
public function behaviors() { return ArrayHelper::merge(parent::behaviors(), ['verbs' => ['class' => VerbFilter::className(), 'actions' => ['delete' => ['post']]], 'access' => ['class' => AccessControl::className(), 'rules' => [['allow' => true, 'actions' => ['index'], 'verbs' => ['GET']], ['allow' => true, 'actions' => ['delete'], 'verbs' => ['POST'], 'roles' => ['@']], ['allow' => true, 'actions' => ['create'], 'roles' => ['@']]]]]); }
/** * @inheritdoc */ public function behaviors() { return Arr::merge(parent::behaviors(), ['access' => ['class' => AccessControl::className(), 'only' => ['logout', 'signup', 'connect'], 'rules' => [['actions' => ['signup', 'connect'], 'allow' => true, 'roles' => ['?']], ['actions' => ['logout'], 'allow' => true, 'roles' => ['@']]]], 'verbs' => ['class' => VerbFilter::className(), 'actions' => ['logout' => ['post']]]]); }