codeigniter-base-model icon indicating copy to clipboard operation
codeigniter-base-model copied to clipboard

Documentation README.md Callbacks/Observers issue

Open arifmahmudrana opened this issue 10 years ago • 0 comments
trafficstars

I think it will be good if you clear this to others.

When we are using callbacks the $row can be object so we better check that so instead of using this,

protected function data_process($row)
{
    $row[$this->callback_parameters[0]] = $this->_process($row[$this->callback_parameters[0]]);

    return $row;
}

use this

protected function data_process($row)
{
  if (is_object($row) && $row->{$this->callback_parameters[0]})//check if object then process
    $row->{$this->callback_parameters[0]} = $this->user_model->order_by('level')->get_many($row->{$this->callback_parameters[0]});
  elseif (is_array($row) && $row[$this->callback_parameters[0]])//check if array then process
    $row[$this->callback_parameters[0]] = $this->user_model->order_by('level')->get_many($row[$this->callback_parameters[0]]);
  return $row;
}

arifmahmudrana avatar Dec 02 '14 09:12 arifmahmudrana