Beispiel #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = BlogTags::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, 'frequency' => $this->frequency]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
 /**
  * Finds the BlogTags model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return BlogTags the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = BlogTags::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Beispiel #3
0
 /**
  * Updates an existing Blog model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $items = $model->getBlogTags()->all();
     $tags = [];
     foreach ($items as $item) {
         $tags[] = $item->name;
     }
     $model->tagNames = BlogTags::array2string($tags);
     //dump(Yii::$app->request->post());
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         $model->image = UploadedFile::getInstance($model, 'image');
         if ($model->image) {
             $path = Yii::getAlias('@webroot/upload/images/blog/') . $model->image->baseName . '.' . $model->image->extension;
             $model->image->saveAs($path);
             $model->attachImage($path);
         }
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('update', ['model' => $model, 'images' => $model->getImages()]);
     }
 }
Beispiel #4
0
 /**
  * @return \yii\db\ActiveQuery
  * Read more at: http://yiiwheels.com/extension/yii2-taggable-behavior
  */
 public function getBlogTags()
 {
     $viaTable = '{{%blog_tags_blog}}';
     return $this->hasMany(BlogTags::className(), ['id' => 'tag_id'])->viaTable($viaTable, ['blog_id' => 'id']);
 }
Beispiel #5
0
 public static function findAllByName($name)
 {
     return BlogTags::find()->where(['like', 'name', $name])->limit(50)->all();
 }