Hey, I’ve got an element that does a requestAction to grab records sorted by date.
What I haven’t been able to workout/find is how to restrict it to only include records who’s date is after now.
For example, in my element I something similar to:
$stuff = $this->requestAction('stuff/get_stuff/sort:my_date/direction:asc');
How should I go about restricting it to only records with my_date after now?
Is their another param I should add or is there something I could add into a find(...) call in my get_stuff action in controller stuff?
Advice or a friendly nudge in the right direction would be grateful!
It really depends on whether or not this will ALWAYS be the action you want to take. But here are a couple of ideas.
You can add a condition to the find query: (Complex Find Conditions)
$this->Stuff->find('all', array('condition' => array('Stuff.my_date >' => date('Y-m-d'))));You can add a beforeFind callback method to the model that implements the same basic process. It will add the condition to every find query for the given model. (beforeFind)