您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

92 行
2.3KB

  1. <?php
  2. namespace frontend\controllers;
  3. use Yii;
  4. use common\models\User;
  5. use yii\data\ActiveDataProvider;
  6. use yii\web\Controller;
  7. use yii\web\NotFoundHttpException;
  8. use yii\filters\VerbFilter;
  9. use yii\filters\AccessControl;
  10. /**
  11. * UserController implements the CRUD actions for User model.
  12. */
  13. class UserController extends Controller
  14. {
  15. public function behaviors()
  16. {
  17. return [
  18. 'verbs' => [
  19. 'class' => VerbFilter::className(),
  20. 'actions' => [
  21. ],
  22. ],
  23. 'access' => [
  24. 'class' => AccessControl::className(),
  25. 'rules' => [
  26. [
  27. 'allow' => true,
  28. 'roles' => ['@'],
  29. /*'matchCallback' => function ($rule, $action) {
  30. return Yii::$app->user->identity->status == USER::STATUS_ADMIN ;
  31. }*/
  32. ]
  33. ],
  34. ],
  35. ];
  36. }
  37. /**
  38. * Updates an existing User model.
  39. * If update is successful, the browser will be redirected to the 'view' page.
  40. * @param integer $id
  41. * @return mixed
  42. */
  43. public function actionUpdate()
  44. {
  45. $model = $this->findModel(Yii::$app->user->identity->id);
  46. if ($model->load(Yii::$app->request->post()) && $model->save()) {
  47. $model->username = $model->email ;
  48. $model->save() ;
  49. return $this->render('update', [
  50. 'model' => $model,
  51. 'edit_ok' => true
  52. ]);
  53. } else {
  54. return $this->render('update', [
  55. 'model' => $model,
  56. ]);
  57. }
  58. }
  59. public function actionCredit()
  60. {
  61. return $this->render('credit', [
  62. ]);
  63. }
  64. /**
  65. * Finds the User model based on its primary key value.
  66. * If the model is not found, a 404 HTTP exception will be thrown.
  67. * @param integer $id
  68. * @return User the loaded model
  69. * @throws NotFoundHttpException if the model cannot be found
  70. */
  71. protected function findModel($id)
  72. {
  73. if (($model = User::findOne($id)) !== null) {
  74. return $model;
  75. } else {
  76. throw new NotFoundHttpException('The requested page does not exist.');
  77. }
  78. }
  79. }