12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <?php
- namespace frontend\controllers;
- use Yii;
- use yii\web\Controller;
- use yii\filters\auth\CompositeAuth;
- use yii\filters\auth\QueryParamAuth;
- class BaseActiveController extends Controller
- {
- public $modelClass = 'common\models\user';
- public $post = null;
- public $get = null;
- public $user = null;
- public $userId = null;
- public function init()
- {
- parent::init();
- Yii::$app->user->enableSession = false;
- }
- public function behaviors()
- {
- $behaviors = parent::behaviors();
- $behaviors['authenticator'] = [
- 'class' => CompositeAuth::className(),
- 'authMethods' => [
- // HttpBasicAuth::className(),
- // HttpBearerAuth::className(),
- QueryParamAuth::className(),
- ],
- ];
- // 数据返回类型设置
- //$behaviors['contentNegotiator']['formats']['application/json'] = 'json';
- //$behaviors['contentNegotiator']['formats']['application/xml'] = 'json';
- return $behaviors;
- }
- public function beforeAction($action)
- {
- parent::beforeAction($action);
- $this->post = yii::$app->request->post();
- $this->get = yii::$app->request->get();
- $this->user = yii::$app->user->identity;
- $this->userId = Yii::$app->user->id;
- return $action;
- }
- }
|