/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = PagePartial::find(); $query->andFilterWhere(['language' => Yii::$app->language]); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 50]]); // Join the entity model as a relation $query->joinWith(['translations']); // enable sorting for the related column $dataProvider->sort->attributes['name'] = ['asc' => ['name' => SORT_ASC], 'desc' => ['name' => SORT_DESC]]; if (!($this->load($params) && $this->validate())) { 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; }
/** * Finds the PagePartial model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return PagePartial the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = PagePartial::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException(Yii::t('app', 'The requested item does not exist')); } }
/** * @return \yii\db\ActiveQuery */ public function getPagePartial() { return $this->hasOne(PagePartial::className(), ['id' => 'page_partial_id']); }