I’m Yii newbie trying to write simple application.
I’m writing “events” module and what I’m trying to achieve is to get data by writing date in URL.
So for example I’ve got URL like this: index.php/event/date/2011-11-19
I created Event controller and It’s working OK. I can even go with index.php/event/1 to load event with PK(id) = 1.
But what I want is to be able to give event_date (field in model/database) and to get all events from this day.
I’ve tried something like this:
public function actionDate($event_date=null) {
$events=Event::model()->findAll("event_date = " . $event_date);
$this->render('view', array(
'model' => $events,
));
}
But I’ve got error: Call to a member function label() on a non-object. Anyone know a way to do this?
Event::model()->findByPk($id);returns single instance of yourEventclass (one object with this$id)When you use
Event::model()->findAll("event_date = " . $event_date);– you work with array of objects, that matches your criteriaSo, try write