You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

136 lines
3.6 KiB

  1. <?php
  2. namespace kcadmin\controllers;
  3. use Yii;
  4. use common\models\Category;
  5. use common\models\CategorySearch;
  6. use yii\web\Controller;
  7. use yii\web\NotFoundHttpException;
  8. use yii\filters\VerbFilter;
  9. /**
  10. * CategoryController implements the CRUD actions for Category model.
  11. */
  12. class CategoryController extends Controller {
  13. public $enableCsrfValidation = false;
  14. /**
  15. * {@inheritdoc}
  16. */
  17. public function behaviors() {
  18. return [
  19. 'verbs' => [
  20. 'class' => VerbFilter::className(),
  21. 'actions' => [
  22. 'delete' => ['POST'],
  23. ],
  24. ],
  25. ];
  26. }
  27. public function actions() {
  28. return [
  29. 'test'=>[
  30. 'class'=>'iron\actions\UploadAction',
  31. ]
  32. ];
  33. }
  34. /**
  35. * Lists all Category models.
  36. * @return mixed
  37. */
  38. public function actionIndex() {
  39. $searchModel = new CategorySearch();
  40. $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
  41. return $this->render('index', [
  42. 'searchModel' => $searchModel,
  43. 'dataProvider' => $dataProvider,
  44. ]);
  45. }
  46. /**
  47. * Displays a single Category model.
  48. * @param integer $id
  49. * @return mixed
  50. * @throws NotFoundHttpException if the model cannot be found
  51. */
  52. public function actionView($id) {
  53. return $this->render('view', [
  54. 'model' => $this->findModel($id),
  55. ]);
  56. }
  57. /**
  58. * Creates a new Category model.
  59. * If creation is successful, the browser will be redirected to the 'view' page.
  60. * @return mixed
  61. */
  62. public function actionCreate() {
  63. $model = new Category();
  64. if ($model->load(Yii::$app->request->post()) && $model->save()) {
  65. return $this->redirect(['view', 'id' => $model->id]);
  66. }
  67. return $this->render('create', [
  68. 'model' => $model,
  69. ]);
  70. }
  71. /**
  72. * Updates an existing Category model.
  73. * If update is successful, the browser will be redirected to the 'view' page.
  74. * @param integer $id
  75. * @return mixed
  76. * @throws NotFoundHttpException if the model cannot be found
  77. */
  78. public function actionUpdate($id) {
  79. $model = $this->findModel($id);
  80. if ($model->load(Yii::$app->request->post()) && $model->save()) {
  81. return $this->redirect(['view', 'id' => $model->id]);
  82. }
  83. return $this->render('update', [
  84. 'model' => $model,
  85. ]);
  86. }
  87. /**
  88. * Deletes an existing Category model.
  89. * If deletion is successful, the browser will be redirected to the 'index' page.
  90. * @param integer $id
  91. * @return mixed
  92. * @throws NotFoundHttpException if the model cannot be found
  93. */
  94. public function actionDelete($id) {
  95. $this->findModel($id)->delete();
  96. return $this->redirect(['index']);
  97. }
  98. /**
  99. *
  100. */
  101. public function actionDeletes() {
  102. //获取前端post的记录id
  103. $ids = Yii::$app->request->post('ids');
  104. }
  105. /**
  106. * Finds the Category model based on its primary key value.
  107. * If the model is not found, a 404 HTTP exception will be thrown.
  108. * @param integer $id
  109. * @return Category the loaded model
  110. * @throws NotFoundHttpException if the model cannot be found
  111. */
  112. protected function findModel($id) {
  113. if (($model = Category::findOne($id)) !== null) {
  114. return $model;
  115. }
  116. throw new NotFoundHttpException('The requested page does not exist.');
  117. }
  118. }