views:

25

answers:

2

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!

+2  A: 

It really depends on whether or not this will ALWAYS be the action you want to take. But here are a couple of ideas.

  1. 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'))));

  2. 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)

cdburgess
A: 

You can create a new method in the controller to find the records you need and just call that, with all the custom parameters in place in the find. Then just ensure that you check it with if($this->params['requested']) to ensure it only comes from your requestAction() call, and return the dataset.

Then ensure that you cache the result, so that you aren't creating a huge overhead on your application by calling a new dispatch cycle every time someone loads the page.

DavidYell