예제 #1
0
 public function search($params)
 {
     $query = Widgets::find()->orderBy('sort');
     $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(['position' => $this->position, 'type' => $this->type]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'bound', $this->bound]);
     return $dataProvider;
 }
예제 #2
0
 protected function findModel($id)
 {
     if ($id === null && ($widget = $this->checkWidget(Yii::$app->request->get('widget'))) !== null) {
         $model = new Widgets();
         $model->widgetModel = new $widget();
         $model->type = Yii::$app->request->get('widget');
         return $model;
     } elseif (($model = Widgets::findOne($id)) !== null && ($widget = $this->checkWidget($model->type)) !== null) {
         $model->widgetModel = new $widget();
         $model->widgetModel->setAttributes(\yii\helpers\Json::decode($model->params));
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }