Skip to content

Instantly share code, notes, and snippets.

@dodopok
Created July 10, 2013 18:20
Show Gist options
  • Save dodopok/5968754 to your computer and use it in GitHub Desktop.
Save dodopok/5968754 to your computer and use it in GitHub Desktop.
Filtros - CakePHP
public function pesquisacheques(){
$this->LancamentoConta->Cheque->recursive = 2;
$this->request->data = $this->request->query;
unset($this->request->data['submit']);
$arraycerta = array();
$pi = false;
foreach($this->request->data as $key => $value){
if($key == 'valor_de' || $key == 'valor_ate'){
if(!$pi){
if(!empty($value)){
$this->request->data['valor_de'] = str_replace(',', '.', str_replace('.', '', str_replace('R$ ', '', $this->request->data['valor_de'])));
$this->request->data['valor_ate'] = str_replace(',', '.', str_replace('.', '', str_replace('R$ ', '', $this->request->data['valor_ate'])));
$key = str_replace('_de', '', $key);
$key = str_replace('_ate', '', $key);
$arraycerta[$key.' >= '] = $this->request->data['valor_de'];
$arraycerta[$key.' <= '] = $this->request->data['valor_ate'];
unset($this->request->data['valor_de']);
unset($this->request->data['valor_ate']);
$pi = true;
}
}
}else{
if(!empty($value)){
$arraycerta['Cheque.'.$key.' LIKE '] = '%'.$value.'%';
}
}
}
$this->request->data = $arraycerta;
$conditions = $this->request->data;
$conditions['Cheque.group_id = '] = $this->Session->read('choosed');
$this->set('cheques', $this->paginate('Cheque',$conditions));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment