Closed dodeagung closed 8 years ago
This module is God send.
I just want to know how to implement the whereClauseArray dynamically
My datatable can do searching, filtering and I need to pass custom where clause on my controller.
Can you show us how to pass custom where statements?
@dodeagung @3s2ng If you want the where clause to change dynamically based on input, you can check the input within the model itself and it will work fine. Here is how I am doing it.
public function whereClauseArray(){
$conditions = array();
if ($this->input->post('year_start')) {
$conditions['year_start >='] = $this->input->post('year_start');
}
if ($this->input->post('year_end')) {
$conditions['year_end <='] = $this->input->post('year_end');
}
if ($this->input->post('skills')) {
$skills = $this->input->post('skills');
foreach ($skills as &$s) {
$s = 'skills LIKE '.$this->db->escape('%'.$s.'%');
}
$conditions['('.implode($skills, ' AND ').')'] = NULL;
}
return $conditions;
}
@TedAvery Thank you for jumping in and helping out! You are exactly right.
@TedAvery How can we set OR condition in whereClauseArray, please let me know if you have any workaround for it.
Hi all, can anyone please help me?
@TedAvery im trying to implement a conditional similar to yours, basically the idea is to restrict city view if user is not admin:
public function whereClauseArray(){ $cond = array(); $is_admin = $this->ion_auth->is_admin(); if( !$is_admin ) { $cond['v.city'] = $this->session->city; } else { $cond = NULL; } return $cond; }
But I got a CI error:
Error Number: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE 0 IS NULL LIMIT 12' at line 2 SELECT *WHERE 0 IS NULL LIMIT 12
Hi Zepernick,
Your plugin superb, thanks very much for your effort to write that!
However, I want to ask you about whereClauseArray(). In you explanation of "Advanced DatatableModel Implementation", you wrote:
'u.id' => $this -> ion_auth -> get_user_id()
can you provide me the details explanation about this line of code?
Since I have similar case, which is the u.Id value would change based on user input.
That's all I want to know.
Best, Agung