hi i want to execute a query whose result should be the input to active data provider. here’s what i have done
public function search_year($params,$year_start,$year_end,$theatre,$movie_name)
{
$userid = \Yii::$app->getRequest()->getCookies()->getValue('users_backend_id');
$mod = Theatres::find()->where(['users_backend_id'=>$userid])->all();//print_r($mod);die();
$moviestable = Movies:: find()->where(['movie_name'=>$movie_name])->one();
if($theatre==null && $movie_name==null)
{
$query1 = new Query;
$query1->select
([
'screen_ticket_booking_history.booking_id As Booking_id',
'screen_ticket_booking_history.booking_date As Booking_date',
'movies.movie_name As Movie',
'theatres.theatre_name As Theatre',
'screen_ticket_booking_history.amount As Amount',
])
->from('screen_ticket_booking_history')
->join('LEFT OUTER JOIN','movies','screen_ticket_booking_history.movie_id=movies.id')
->join('LEFT OUTER JOIN','theatres','screen_ticket_booking_history.theatre_id=theatres.id')
->join('LEFT OUTER JOIN','users_backend','theatres.users_backend_id=users_backend.id')
->where('booking_date >= :start_date', [':start_date' => $year_start])
->andWhere('booking_date <= :end_date', [':end_date' => $year_end])
->andWhere('theatres.users_backend_id = :id', [':id' => $userid]);
$command = $query1->createCommand();
$query = $command->queryAll();
//print_r($query);die();
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
$query->andFilterWhere([
'id' => $this->id,
'booking_id' => $this->booking_id,
'booking_date' => $this->booking_date,
'show_date' => $this->show_date,
'movie_id' => $this->movie_id,
'theatre_id' => $this->theatre_id,
'screen_id' => $this->screen_id,
'show_time_id' => $this->show_time_id,
'amount' => $this->amount,
//~ 'user_id' => $user->id,
'location_id' => $this->location_id,
'created_by' => $this->created_by,
'created_at' => $this->created_at,
'updated_by' => $this->updated_by,
'updated_at' => $this->updated_at,
'is_deleted' => $this->is_deleted,
]);
$query->andFilterWhere(['like', 'booking_id', $this->booking_id])
->andFilterWhere(['like', 'email', $this->email])
->andFilterWhere(['like', 'mobile', $this->mobile])
->andFilterWhere(['like', 'seat_info', $this->seat_info]);
return $dataProvider;
}
but i am getting a error like
Call to a member function andFilterWhere() on a non-object
when i printed the result of the query there are values in there.