mercredi 30 novembre 2016

Silverstripe 3 - Filter dataobjeccts with checkboxes

I am trying to filter dataobject results based on checkbox selection.

If a user checks 'pool' and 'garage' I would like all items to display with a pool and a garage. At the moment only one or the other works but not together.

Something similar to: http://ift.tt/2gUymFr but without the Ajax.

Is this the correct way to go about this?

public function index(SS_HTTPRequest $request) {
$properties = Property::get();

   if($pool= $request->getVar('pool')) {
        $properties= $properties
        ->filter(array(
            'Title' => 'pool'              
        ));
    }

if($garage= $request->getVar('garage')) {
        $properties= $properties
        ->filter(array(
            'Title' => 'garage'              
        ));
    }

return array (
    'Results' => $properties
);
}




Aucun commentaire:

Enregistrer un commentaire