DopomogaController.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace app\controllers;
  3. use app\models\HelpCategory;
  4. use app\models\HelpVideo;
  5. use Yii;
  6. use app\models\Help;
  7. use app\models\HealpSearch as HelpSearch;
  8. use yii\data\ActiveDataProvider;
  9. use yii\web\Controller;
  10. use yii\web\NotFoundHttpException;
  11. use yii\filters\VerbFilter;
  12. use yii\filters\AccessControl;
  13. /**
  14. * HelpController implements the CRUD actions for Help model.
  15. */
  16. class DopomogaController extends Controller
  17. {
  18. /**
  19. * @inheritdoc
  20. */
  21. public function behaviors()
  22. {
  23. return [
  24. 'verbs' => [
  25. 'class' => VerbFilter::className(),
  26. 'actions' => [
  27. 'delete' => ['POST'],
  28. ],
  29. ],
  30. ];
  31. }
  32. /**
  33. * Lists all Help models.
  34. * @return mixed
  35. */
  36. public function actionIndex()
  37. {
  38. $dataProvider = new ActiveDataProvider([
  39. 'query' => HelpCategory::find(),
  40. ]);
  41. return $this->render('index',[
  42. 'dataProvider' =>$dataProvider,
  43. ]);
  44. }
  45. public function actionCategory($slug)
  46. {
  47. $category = HelpCategory::findOne(['slug' => $slug]);
  48. $videos = HelpVideo::findAll(['cat_id' => $category->id]);
  49. $title = $category->title;
  50. $key = $category->key_words;
  51. $desc = $category->description;
  52. $this->view->title = $title;
  53. $this->view->registerMetaTag(['name' => 'keywords', 'content' => $key]);
  54. $this->view->registerMetaTag(['name' => 'description', 'content' => $desc]);
  55. $dataProvider = new ActiveDataProvider([
  56. 'query' => Help::find()->where(['cat_id' => $category->id]),
  57. 'pagination' => [
  58. 'defaultPageSize' => 5,
  59. ],
  60. 'sort' => [
  61. 'defaultOrder' => [
  62. 'id' => SORT_DESC,
  63. ],
  64. ],
  65. ]);
  66. return $this->render('category',[
  67. 'dataProvider' => $dataProvider,
  68. 'videos' => $videos,
  69. ]);
  70. }
  71. public function actionView($slug)
  72. {
  73. if (false != ($model = Help::findOne(['slug' => $slug]))) {
  74. return $this->render('view', [
  75. 'model' => $model,
  76. ]);
  77. } else {
  78. throw new NotFoundHttpException(Yii::t('app', 'Post not found'));
  79. }
  80. }
  81. }