Auto Condition By Today's Date

I had to delete the previous topic because the plan was changed a bit.

In the form of Person_Event model I need to show a cGridView of Event model , BUT , only those which occur on this Week model.

So here is the code I came up with in the Person_Event form (is it appropriate to put it there?) , but I get an SQL syntax error that $week_id doesn’t have a value.

I’m not quite sure about some lines , so I marked them with my questions:



	$today=date("Y-m-d");                    // does it really give today's date?


	$criteria = new CDbCriteria();  

	$criteria->condition='start_date<=:today AND end_date>=:today';     //check that today's date is in a certain week?

	$criteria->params = array(':today'=>$today);

	$week = Week::model()->findAll($criteria);          //finds the week?


	$week_id=$week->id;                               //takes the  week's id?


	$this->widget('ext.selgridview.SelGridView', array(


	'selectableRows' =>2,

	'dataProvider'=>Event::model()->search(array('condition'=>"type_id='conference' AND week_id=$week_id")), 


        //rest of the CgridView. . . . . 

hello MarkBrass. findAll() returns array of objects. you are assigning the week id like $week_id=$week->id; it wont works change it to something like this $week[0]->id or use find() instead of findAll()

Hello Ahamed, Understood. Tried both changes but I still get the error:

check the week first like print_r($week); and see the results what it was returned. I think there is no results returned for Week model

you are not checking whether the Week model returns any results or not you are directly assigning week_id without checking the empty array. so check the result returned by Week model then assign it. you are getting the error because there is no event available for $today so the result will return empty array()

Oh , right. totally forgot. . . :D Now it is working well.

Thank you very much!