Esempio n. 1
0
 public function search($params)
 {
     /**
      * Добавить в запрос поиска колонку дополнительной модели
      * (по названию связи)
      */
     $query = Cube::find()->joinWith(['friend']);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     /**
      * Добавить сортировку по дополнительной колонке
      */
     $dataProvider->sort->attributes['friend'] = ['asc' => ['name' => SORT_ASC], 'desc' => ['name' => SORT_DESC]];
     $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]);
     /**
      * Добавить часть запроса при поиске по дополнительной колонке
      */
     $query->andFilterWhere(['like', 'cube.name', $this->name]);
     $query->andFilterWhere(['like', 'friend.name', $this->friend]);
     return $dataProvider;
 }
Esempio n. 2
0
 public function getCube()
 {
     return $this->hasOne(Cube::className(), ['id' => 'cube_id'])->inverseOf('friend');
 }
 /**
  * Finds the Cube model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Cube the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Cube::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }