Convert Yii 1.1 query to Yii 2.


I’m having a hard time to replicate this exactly same query in Yii 2. I’ve spent the entire afternoon on this and nothing yet.

This is my query

$criteria=new CDbCriteria;

$criteria->condition = "t.driver_id = $driver->driver_id AND (job.current_status = 'Driver Assigned' OR job.current_status = 'Relay' OR job.current_status = 'Order Accepted' OR job.current_status = 'Start Waiting' OR job.current_status = 'Loading' OR job.current_status = 'In Transit' OR job.current_status = 'Unloading')";

$criteria->order = "job.order_eta";

$jobdrivermodel = JobDrivers::model()->with(array('job','driver'))->findAll($criteria);

and I tried this and other options but it didn’t work:

$jobdrivermodel = JobDrivers::find()

->where(['driver_id' => $driver->driver_id])


->andWhere('current_status = :driverassigned', [':driverassigned' => \Yii::$app->params['driverassigned']])

->orWhere('current_status = :relay', [':relay' => \Yii::$app->params['relay']])

->orWhere('current_status = :orderaccepted', [':orderaccepted' => \Yii::$app->params['orderaccepted']])

->orWhere('current_status = :startwaiting', [':startwaiting' => \Yii::$app->params['startwaiting']])

->orWhere('current_status = :loading', [':loading' => \Yii::$app->params['loading']])

->orWhere('current_status = :unloading', [':unloading' => \Yii::$app->params['unloading']])

->orWhere('current_status = :intransit', [':intransit' => \Yii::$app->params['intransit']])


Can anyone help me please? I’m desperate.

Try this:

$jobdrivermodel = JobDrivers::find()

  ->where(['driver_id' => $driver->driver_id])




    ['current_status' => \Yii::$app->params['driverassigned']],

    ['current_status' => \Yii::$app->params['relay']],

    ['current_status' => \Yii::$app->params['orderaccepted']],




Check the operator format of where(). The operands in array format can be sub conditions of the operator.

My friend thank you so much. It worked!!! THank thank you thank you!