2017-02-22 9 views
0

質問は混乱しますが、私は説明します。 私はAsistenciaSearch.phpYii 2のコントローラから1つの検索モデルのフィルタを1つのfindModelにマージする方法は?

public function search($params) 
    { 
     $query = Asistencia::find(); 

     // add conditions that should always apply here 

     $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->joinWith('rutAlumno0'); 
     $query->joinWith('idPlanificacion0'); 

     // grid filtering conditions 
     $query->andFilterWhere([ 
      'idAsistencia' => $this->idAsistencia, 
      //'idPlanificacion' => $this->idPlanificacion, 
     ]); 

     $query->andFilterWhere(['like', 'asistencia', $this->asistencia]) 
      ->andFilterWhere(['like', 'rutAlumno', $this->rutAlumno]) 
      //->andFilterWhere(['like', 'idPlanificacion', $this->idPlanificacion]) 
      ->andFilterWhere(['like', 'alumno.nombreAlumno', $this->nombreAlumno]) 
      ->andFilterWhere(['like', 'alumno.apellidoAlumno', $this->apellidoAlumno]) 
      ->andFilterWhere(['like', 'alumno.cursoAlumno', $this->cursoAlumno]) 
      ->andFilterWhere(['like', 'alumno.establecimientoAlumno', Yii::$app->user->identity->escuelaProfesor]); 


     return $dataProvider; 
    } 

からこの検索クエリを持っており、このPlanificacionController.phpで検索クエリを使用してコントローラ機能:

public function actionVerasistencia($id) 
    { 
     $searchModel = new AsistenciaSearch(); 
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams); 

     return $this->render('verasistencia', [ 
      'model' => $this->findModel($id), //findModel from Planificacion 
      'searchModel' => $searchModel, 
      'dataProvider' => $dataProvider, 
     ]); 
    } 

AsistenciaとPlanificacion両方がPlanificacionの主キーを使用して関連しているが、idPlanificacionと名付けられ、同じ名前を使ってAsistenciaのそのモデルからの外部キー。質問がある は、私はこのようなfindModel($ id)で$ idは、検索クエリから$ idPlanificacionのようなものです別のフィルタ、との合併にする必要があります。

public function actionVerasistencia($id) 
    { 
     $searchModel = new AsistenciaSearch(); 
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams); 

     return $this->render('verasistencia', [ 
      'model' => $this->findModel($id), 
      'searchModel' => $searchModel, 
      'dataProvider' => $dataProvider->andFilterWhere('like',$id,$this->idPlanificacion), 
     ]); 
    } 

しかし、私はこのエラーを得ました:

Getting unknown property: frontend\controllers\PlanificacionController::idPlanificacion 

どのような解決策ですか?コントローラ内部の

答えて

1

$これはidPlanificacionエイリアスを参照するコントローラ自身 が、あなたのアールに関連しているあなたは

はあなたがモデル等により値をretriveたいことができモデル属性を参照している:

$model = $this->findModel($id) 

public function actionVerasistencia($id) 
    { 
     $searchModel = new AsistenciaSearch(); 
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams); 

     $model = $this->findModel($id); 
     return $this->render('verasistencia', [ 
      'model' =>$model, 
      'searchModel' => $searchModel, 
      'dataProvider' => $dataProvider->andFilterWhere('like',$id,$model->idPlanificacion), 
     ]); 
    } 
関連する問題