UserController.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace api\controllers\v1;
  3. use yii\rest\ActiveController;
  4. use yii\filters\auth\QueryParamAuth;
  5. /**
  6. * 这里注意是继承 yii\rest\ActiveController 因为源码中已经帮我们实现了index/update等方法
  7. * 以及其访问规则verbs()等,
  8. * 其他可参考:http://www.yiichina.com/doc/guide/2.0/rest-controllers
  9. *
  10. * 权限采用最简单的QueryParamAuth方式
  11. * 用户角色权限比较复杂,这里没有做
  12. *
  13. * @package api\modules\v1\controllers
  14. */
  15. class UserController extends ActiveController
  16. {
  17. public $modelClass = 'common\models\xhUser';
  18. public function behaviors()
  19. {
  20. $behaviors = parent::behaviors();
  21. /* 设置认证方式 */
  22. /*$behaviors['authenticator'] = [
  23. 'class' => QueryParamAuth::className(),
  24. ];*/
  25. return $behaviors;
  26. }
  27. public function actions()
  28. {
  29. $action= parent::actions(); // TODO: Change the autogenerated stub
  30. unset($action['index']);
  31. unset($action['create']);
  32. unset($action['update']);
  33. unset($action['delete']);
  34. }
  35. public function actionIndex()
  36. {
  37. return ['status'=>201, 'msg'=>'success'];
  38. }
  39. }