Use ternary php operators to check what the user selects, put them
into a variable and attach that into the conditions;

$condition = isset($this->data['Search']['Stars']) ?
array('Offer.flag_stars' => $this->data['Search']['stars']) : '';

$results = $this->Offer->find('all', array(
                                    'conditions' => $conditions,
                   ));

Again you can add multiple $condition - just append them into the
array. Also you don't need to specify every individual field - cake's
find('all'); selects all the fields from a table. Use containable
behavior if you want limit the results you get



On Jul 8, 9:57 am, viciat <viciuasc...@yahoo.com> wrote:
> I want to let the user select the parameters he wants to search for.
>
> There are 4 different types of values he can select.
>
> stars, category, price and date.
>
> But I want to give him the opportunity to search for only one of those. For
> example, if he selects 0 for stars, I want to disregard that criteria. If he
> selects Whatever from categories, I also want to disregard that criteria.
> The same for the price and period. How can I build this?
>
> How to I build the search function ?
>
>                         $results = $this->Offer->find('all', array(
>                                     'conditions' => array(
>                                         'Offer.flag_stars' => 
> $this->data['Search']['stars'],
>                                         'Offer.location_id' => 
> $this->data['Search']['location_id'],
>                                                 'NOW() between ? and ?' => 
> array($this->data['Search']['starts'],
> $this->data['Search']['expires'])
>                                     ),
>                                     'fields' =>
> array('Offer.id','Offer.name','Offer.description','Offer.flag_stars','Offer 
> .flag_stars_plus','Offer.flag_starting_price','Offer.flag_price_currency',' 
> Offer.description_sejour','Offer.countries','Offer.duration','Offer.type',' 
> Offer.created','Offer.starts','Offer.expires'),
>                                     'order' => 'Offer.flag_stars ASC',
>                                 ));
>
> --
> View this message in 
> context:http://old.nabble.com/Add-to-model-conditions-tp29103124p29103124.html
> Sent from the CakePHP mailing list archive at Nabble.com.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to