how can I filter data cumulatively in CakePHP -



how can I filter data cumulatively in CakePHP -

i'm relatively new cakephp , object oriented programming. have built apps in cakephp before, never extent, hence reason i'm asking help.

i have big product management database, user needs able set filter criteria find closest product matches.

the products table contains category_id, manufacturer_id, type_id, status_id related respective tables.

i have sidebar dropdown boxes each filter, , want filters work together, instance, if manufacturer , product type selected, display filtered results, , alter status , category dropdowns contain options filtered results.

in past have accomplished using dynamic query setting conditions based on user input, appending clauses each time filter applied.

so far i've been able individually filtered results using

$this->product->recursive = 0; $mid = (isset($this->params['named']['mid'])) ? $this->params['named']['mid'] : ''; if(!empty($mid)){ $this->paginate = array( 'conditions' => array('product.manufacturer_id' => $mid), 'limit' => 10 ); } $products = $this->paginate('product'); $this->set(compact('products'));

where 'mid' manufacturer id, , manually entering 'mid' in url

how cumulatively filter results if user sets category_id, manufacturer_id, type_id, status_id or combination? , queries utilize repopulate dropdowns?

(eventually utilize ajax, assume have 4 dropdown boxes submit button)

the long way be:

var $conditions = array(); if (isset($this->params['named']['mid']) && !empty($this->params['named']['mid'])){ $conditions['product.manufacturer_id'] = $this->params['named']['mid']); } if (isset($this->params['named']['catid']) && !empty($this->params['named']['catid'])){ $conditions['product.category_id'] = $this->params['named']['catid']); } if (isset($this->params['named']['statid']) && !empty($this->params['named']['statid'])){ $conditions['product.status_id'] = $this->params['named']['statid']); } $this->paginate['conditions'] = $conditions; $this->paginate['limit'] = '10'; $this->set('products', $this->paginate('product'));

once hang of that, set checks loop.

cakephp

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -