SuggestController.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace backend\controllers;
  3. use common\models\Suggest;
  4. use yii\data\ActiveDataProvider;
  5. use yii\filters\VerbFilter;
  6. use yii\web\Controller;
  7. use yii\web\NotFoundHttpException;
  8. use Yii;
  9. /**
  10. * SuggestController implements the CRUD actions for Suggest model.
  11. */
  12. class SuggestController extends Controller
  13. {
  14. public function behaviors()
  15. {
  16. return [
  17. 'verbs' => [
  18. 'class' => VerbFilter::className(),
  19. 'actions' => [
  20. 'delete' => ['post'],
  21. ],
  22. ],
  23. ];
  24. }
  25. /**
  26. * Lists all Suggest models.
  27. * @return mixed
  28. */
  29. public function actionIndex()
  30. {
  31. $dataProvider = new ActiveDataProvider([
  32. 'query' => Suggest::find(),
  33. 'sort' => [
  34. 'defaultOrder' => [
  35. 'id' => SORT_DESC
  36. ]
  37. ]
  38. ]);
  39. return $this->render('index', [
  40. 'dataProvider' => $dataProvider,
  41. ]);
  42. }
  43. /**
  44. * Displays a single Suggest model.
  45. * @param integer $id
  46. * @return mixed
  47. */
  48. public function actionView($id)
  49. {
  50. return $this->render('view', [
  51. 'model' => $this->findModel($id),
  52. ]);
  53. }
  54. /**
  55. * Deletes an existing Suggest model.
  56. * If deletion is successful, the browser will be redirected to the 'index' page.
  57. * @param integer $id
  58. * @return mixed
  59. */
  60. public function actionDelete($id)
  61. {
  62. $this->findModel($id)->delete();
  63. return $this->redirect(Yii::$app->request->getReferrer());
  64. }
  65. /**
  66. * Finds the Suggest model based on its primary key value.
  67. * If the model is not found, a 404 HTTP exception will be thrown.
  68. * @param integer $id
  69. * @return Suggest the loaded model
  70. * @throws NotFoundHttpException if the model cannot be found
  71. */
  72. protected function findModel($id)
  73. {
  74. if (($model = Suggest::findOne($id)) !== null) {
  75. return $model;
  76. } else {
  77. throw new NotFoundHttpException('The requested page does not exist.');
  78. }
  79. }
  80. }