コード例 #1
0
ファイル: VideoController.php プロジェクト: Akelcehg/psycho
 public function actionIndex()
 {
     $searchModel = new VideosSearch();
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     $dataProvider->pagination->pageSize = 6;
     return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'videosCategories' => VideosCategories::find()->all(), 'popularVideos' => Videos::getPopularVideos()]);
 }
コード例 #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = VideosCategories::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
コード例 #3
0
ファイル: VideosController.php プロジェクト: Akelcehg/psycho
 /**
  * Creates a new Videos model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Videos();
     //var_dump(strpos('https://www.youtube.com/watch?v=gDAY1Tfc-zY', 'youtube'));
     //https://www.youtube.com/watch?v=gDAY1Tfc-zY
     //http://img.youtube.com/vi/gDAY1Tfc-zY/mqdefault.jpg
     if ($model->load(Yii::$app->request->post())) {
         $model->user_id = Yii::$app->user->id;
         $model->img_link = $model->getVideoImage($model->link);
         $model->link = $model->getEmbedLink($model->link);
         $videoCategories = new VideosCategories();
         if ($model->save()) {
             if ($videoCategories->saveVideosCategories($model->id, Yii::$app->request->post('categories'))) {
                 return $this->redirect(['view', 'id' => $model->id]);
             }
         } else {
             return $this->render('create', ['model' => $model, 'videosCategories' => VideosCategories::find()->all()]);
         }
     } else {
         return $this->render('create', ['model' => $model, 'videosCategories' => VideosCategories::find()->all()]);
     }
 }