Skip to content

Commit

Permalink
Bug Fix: Message: Cannot access protected property CI_DB_mysqli_drive…
Browse files Browse the repository at this point in the history
…r::$_protect_identifiers. This was not compatible with CI 3.

added check for global search via the "search" param
  • Loading branch information
zepernick committed Jun 17, 2015
1 parent 6bfa376 commit bf85a97
Showing 1 changed file with 40 additions and 11 deletions.
51 changes: 40 additions & 11 deletions libraries/Datatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ public function datatableJson($formats = array(), $debug = FALSE) {
$this -> CI -> db -> limit($limit, $start);
$query = $this -> CI -> db -> get();

$jsonArry = array();

if(!$query) {
$jsonArry['errorMessage'] = $this -> CI -> db -> _error_message();
return $jsonArry;
Expand Down Expand Up @@ -269,7 +271,6 @@ public function datatableJson($formats = array(), $debug = FALSE) {



$jsonArry = array();
$jsonArry['start'] = $start;
$jsonArry['limit'] = $limit;
$jsonArry['draw'] = (int)$f -> post('draw');
Expand Down Expand Up @@ -328,7 +329,8 @@ private function formatValue($formats, $column, $value) {
//fetch the data and get a total record count
private function sqlJoinsAndWhere() {
$debug = '';
$this -> CI -> db-> _protect_identifiers = FALSE;
// this is protected in CI 3 and can no longer be turned off. must be turned off in the config
// $this -> CI -> db-> _protect_identifiers = FALSE;
$this -> CI -> db -> from($this -> model -> fromTableStr());

$joins = $this -> model -> joinArray() === NULL ? array() : $this -> model -> joinArray();
Expand All @@ -347,26 +349,53 @@ private function sqlJoinsAndWhere() {
$this -> model -> appendToSelectStr();

$f = $this -> CI -> input;

$searchableColumns = array();
foreach($f -> post('columns') as $c) {

$colName = $c['data'];

if(substr($colName, 0, 2) === '$.') {
$aliasKey = substr($colName, 2);
if(isset($customExpArray[$aliasKey]) === FALSE) {
throw new Exception('Alias['. $aliasKey .'] Could Not Be Found In appendToSelectStr() Array');
}

$colName = $customExpArray[$aliasKey];
}

if($c['searchable'] !== 'false') {
$searchableColumns[] = $colName;
}

if($c['search']['value'] !== '') {
$colName = $c['data'];
$searchType = $this -> getColumnSearchType($colName);
//log_message('info', 'colname[' . $colName . '] searchtype[' . $searchType . ']');
//handle custom sql expressions/subselects
if(substr($colName, 0, 2) === '$.') {
$aliasKey = substr($colName, 2);
if(isset($customExpArray[$aliasKey]) === FALSE) {
throw new Exception('Alias['. $aliasKey .'] Could Not Be Found In appendToSelectStr() Array');
}

$colName = $customExpArray[$aliasKey];
}

$debug .= 'col[' . $c['data'] .'] value[' . $c['search']['value'] . '] ' . PHP_EOL;
// log_message('info', 'colname[' . $colName . '] searchtype[' . $searchType . ']');
$this -> CI -> db -> like($colName, $c['search']['value'], $searchType);
}
}



// put together a global search if specified
$globSearch = $f -> post('search');
if($globSearch['value'] !== '') {
$gSearchVal = $globSearch['value'];
$sqlOr = '';
$op = '';
foreach($searchableColumns as $c) {
$sqlOr .= $op . $c . ' LIKE \'' . $this->CI->db->escape_like_str($gSearchVal) . '%\'';
$op = ' OR ';
}

$this -> CI -> db -> where('(' . $sqlOr . ')');
}


//append a static where clause to what the user has filtered, if the model tells us to do so
$wArray = $this -> model -> whereClauseArray();
if(is_null($wArray) === FALSE && is_array($wArray) === TRUE && count($wArray) > 0) {
Expand Down

0 comments on commit bf85a97

Please sign in to comment.