SubscriptionsController.php 2.2 KB

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