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.

76 lines
1.8 KiB

  1. <?php
  2. namespace backend\controllers;
  3. use Yii;
  4. use backend\models\ars\Category;
  5. use yii\web\Controller;
  6. use yii\web\NotFoundHttpException;
  7. use yii\filters\VerbFilter;
  8. /**
  9. * CategoryController implements the CRUD actions for Category model.
  10. */
  11. class ConfigController extends Controller
  12. {
  13. /**
  14. * {@inheritdoc}
  15. */
  16. public function behaviors()
  17. {
  18. return [
  19. 'verbs' => [
  20. 'class' => VerbFilter::className(),
  21. 'actions' => [
  22. 'delete' => ['POST'],
  23. ],
  24. ],
  25. ];
  26. }
  27. /**
  28. * Lists all Category models.
  29. * @return mixed
  30. */
  31. public function actionIndex()
  32. {
  33. return $this->render('index');
  34. }
  35. /**
  36. * Updates an existing Category model.
  37. * If update is successful, the browser will be redirected to the 'view' page.
  38. * @param integer $id
  39. * @return mixed
  40. * @throws NotFoundHttpException if the model cannot be found
  41. */
  42. public function actionUpdate($id)
  43. {
  44. $model = $this->findModel($id);
  45. if ($model->load(Yii::$app->request->post()) && $model->save()) {
  46. return $this->redirect('index');
  47. }
  48. return $this->render('update', [
  49. 'model' => $model,
  50. ]);
  51. }
  52. /**
  53. * Finds the Category model based on its primary key value.
  54. * If the model is not found, a 404 HTTP exception will be thrown.
  55. * @param integer $id
  56. * @return Category the loaded model
  57. * @throws NotFoundHttpException if the model cannot be found
  58. */
  59. protected function findModel($id)
  60. {
  61. if (($model = Category::findOne($id)) !== null) {
  62. return $model;
  63. }
  64. throw new NotFoundHttpException('The requested page does not exist.');
  65. }
  66. }