Hello,
I’m having troubles when I try to display left joined fields inside view, since they’re not in the model I search in. What would you suggest me to do?
Here’s what I have:
Model of AvailabilityCalendarSearch (Where I’m doing the join):
public function search($params)
{
$query = AvailabilityCalendar::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
'sort' => [
'defaultOrder' => [
'ac_price' => SORT_ASC,
]
],
]);
if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}
$query->andFilterWhere([
'ac_id' => $this->ac_id,
'ac_owner_id' => $this->ac_owner_id,
'ac_position' => $this->ac_position,
'ac_date' => $this->ac_date,
//'ac_start_time' => $this->ac_start_time,
'ac_price' => $this->ac_price,
'ac_status' => $this->ac_status,
]);
$query->andFilterWhere(['<', 'ac_start_time', $this->ac_start_time]);
$query->leftJoin('employees', 'availability_calendar.ac_owner_id = employees.employee_user_id');
return $dataProvider;
}
Controller Search :
public function actionSearchemployees()
{
$model = new AvailabilityCalendarSearch;
$svar = 0;
echo "xpar=".print_r(Yii::$app->request->queryParams);
if ($model->load(Yii::$app->request->get())) {
//echo "xpost";
$svar = 1;
$dataProvider = $model->search(Yii::$app->request->queryParams);
return $this->render('searchemployees', [
'model' => $model,
'dataProvider' => $dataProvider,
'svar' =>$svar
]);
} else {
//echo "xpost2";
return $this->render('searchemployees', [
'model' => $model,
'svar' =>$svar
]);
}
}
and I’m trying to display joined field employee_firstname
<?= GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'ac_position',
'ac_date',
'ac_start_time',
'ac_price',
'employee_firstname',
['class' => 'yii\grid\ActionColumn'],
],
]); }?>
it says that employee_firstname is not a part of the model… which is right
I just don’t know how to implement it, please advice!
Thank you!!!