protected function findModel($id)
 {
     if (($model = FragmentCategory::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 public function search($params)
 {
     $query = FragmentCategory::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'type' => $this->type, 'sort_num' => $this->sort_num]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
 public function actionUpdate($id, $type)
 {
     $model = $this->findModel($id);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['index', 'type' => $model->type]);
     } else {
         $locals = [];
         $locals['model'] = $model;
         $locals['categories'] = FragmentCategory::findAll(['type' => $type]);
         $locals['type'] = $type;
         return $this->render('update', $locals);
     }
 }