Search params

Hi Folks,

First post and all that, so a bit of an intro: I interviewed a guy the other day and he mentioned he used Yii. He said it was good, so I decided to give it a go for a little project we have. Must say, I am impressed. I’ve pulled together the bulk of the application in a weekend, and I budgeted a week for the app in Zend!

Question:

I have controller/view that displays “appointments”, but I need to create a pair that only shows appointments for ‘today’.

From poking about, it seems sensible to create a custom search method on the model, but I’m not sure how to essentially add a WHERE clause to the CActiveDataProvider. I need to make sure the “appointment_time” is today. It’s a mysql timestamp, so probably best with a between query.

What I currently have:

	return new CActiveDataProvider($this, array(


		'criteria'=>$criteria,


		'sort'=>array(


        'attributes'=>array(


            'clientName'=>array(


                'asc'=>'client.company',


                'desc'=>'client.company DESC',


            ),


            '*',...

Thank you for any help,

Nathan

Add a condition clause to your $criteria array.

Thanks, got me in the right direction, I think.

I’ve added

$criteria->addBetweenCondition(‘appointment_time’, date(‘Y-m-d 00:00:00’), date(‘Y-m-d 23:59:59’));

To my searchToday() method.

The today action look thus:

public function actionToday()


{


	$model=new Appointment('searchToday');


	$model->unsetAttributes();  // clear any default values


	if(isset($_GET['Appointment']))


		$model->attributes=$_GET['Appointment'];





	$this->render('admin',array(


		'model'=>$model,


	));		


}

But it doesn’t seem to be making a difference to the results.

I’m confused :)

Nevermind, sorted it.

$this->render(‘admin’,array(

‘model’=>$model,

));

Was pointing to the wrong view.

Thanks for shunting me in the right direction. I would have struggled without a prompt.

Cheers

I’ve been there :)

If you aren’t using the ‘debug toolbar’ extension for development I highly recommend it. Turn on DB profiling and you will see query times and SQL used for the query. It is VERY useful for helping translate complex sql into active record objects because you can see what Yii is generating.