Yii Framework Forum: Auto Condition By Today's Date - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Auto Condition By Today's Date Rate Topic: -----

#1 User is offline   MarkBrass 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 130
  • Joined: 13-November 13

Posted 29 March 2014 - 10:26 AM

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:

<?php 
	
	$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(
	'id'=>'event-grid',
	'selectableRows' =>2,
	'dataProvider'=>Event::model()->search(array('condition'=>"type_id='conference' AND week_id=$week_id")), 
	'columns'=>array(
        //rest of the CgridView. . . . . 

0

#2 User is offline   Ahamed Rifaideen 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 379
  • Joined: 14-February 13
  • Location:chennai, tamilnadu

Posted 29 March 2014 - 10:37 AM

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()
My Blog - Yii Learner
0

#3 User is offline   MarkBrass 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 130
  • Joined: 13-November 13

Posted 29 March 2014 - 11:30 AM

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

Quote

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1. The SQL statement executed was: SELECT COUNT(*) FROM `tbl_event` `t` WHERE type_id='conference' AND week_id=

0

#4 User is offline   Ahamed Rifaideen 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 379
  • Joined: 14-February 13
  • Location:chennai, tamilnadu

Posted 29 March 2014 - 12:09 PM

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
My Blog - Yii Learner
0

#5 User is offline   Ahamed Rifaideen 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 379
  • Joined: 14-February 13
  • Location:chennai, tamilnadu

Posted 29 March 2014 - 12:13 PM

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()
My Blog - Yii Learner
0

#6 User is offline   MarkBrass 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 130
  • Joined: 13-November 13

Posted 29 March 2014 - 12:58 PM

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

Thank you very much!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users