Example #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = PostImageRel::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'post_id' => $this->post_id]);
     $query->andFilterWhere(['like', 'image', $this->image])->andFilterWhere(['like', 'short_title', $this->short_title])->andFilterWhere(['like', 'short_desc', $this->short_desc]);
     return $dataProvider;
 }
Example #2
0
 /**
  * Updates an existing Post model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate()
 {
     if (Yii::$app->request->isAjax) {
         if (isset($_POST['id'])) {
             $id = $_POST['id'];
             $model = $this->findModel($id);
         }
         if (isset($_POST['Post'])) {
             $model = $this->findModel($_POST['Post']['id']);
             $model->attributes = $_POST['Post'];
             if ($model->save()) {
                 $response['files'] = ['ok'];
                 $response['result'] = 'success';
                 $response['post_list'] = $this->renderAjax('list_of_post', ['page_id' => $model->page_id]);
                 return json_encode($response);
             } else {
                 $response['result'] = 'error';
                 $response['files'] = Html::errorSummary($model);
                 return json_encode($response);
             }
         } else {
             $response['id'] = $model->id;
             $response['post_title'] = $model->post_title;
             $response['desc'] = $model->desc;
             $response['upload_view'] = $this->renderAjax('file_upload_view', ['post_id' => $model->id]);
             $images = PostImageRel::find()->where(['post_id' => $model->id])->all();
             $response['images_list'] = $this->renderAjax('uploaded_image_list', ['images' => $images]);
             return json_encode($response);
         }
     }
 }
 /**
  * Finds the PostImageRel model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return PostImageRel the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = PostImageRel::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Example #4
0
 public function getPost_image_rel()
 {
     return $this->hasMany(PostImageRel::className(), ['post_id' => 'id']);
 }