Home Ask Login Register

Developers Planet

Your answer is one click away!

yashen February 2016

Fatal error. Cannot use object of type stdClass as array in C:\xampp\htdocs\system\libraries\Table.php on line 256

I'm getting this error when i try to execute 2 function in the same controller. the 1st one works fine, but get the error

'Fatal error. Cannot use object of type stdClass as array in C:\xampp\htdocs\system\libraries\Table.php on line 256'.

Controller

<?phpif (!defined('BASEPATH'))
exit('No direct script access allowed'); class tables extends CI_Controller {

public function __construct() {
    parent::__construct();
    $this->load->helper('url');
    $this->load->helper('form');
    $this->load->library('session');
    $this->load->library('table');
    $this->load->library('pagination');
    $this->load->database();
    //load the search model
    $this->load->model('mtables');
}

public function index() {

}

public function current_users() {

    $config = array();
    $config["base_url"] = base_url() . "tables/current_users";

    $table = 'dept_officer_view';
    $total_row = $this->mtables->record_count($table);

    $config["total_rows"] = $total_row;
    $config["per_page"] = 10;
    $config['use_page_numbers'] = TRUE;
    $config['num_links'] = 20;
    $config['cur_tag_open'] = '&nbsp;<a class="current">';
    $config['cur_tag_close'] = '</a>';
    $config['next_link'] = 'Next';
    $config['prev_link'] = 'Previous';

    $this->pagination->initialize($config);
    $result_per_page = 10;
    $data["links"] = explode('&nbsp;', $str_links);

    $datatable1 = $this->mtables->fetch_data($result_per_page, $this->uri->segment(3), $table);
    $this->load->view('header');
    $this->load->view('dept_officer_table_view', array(
        'datatable1' => $datatable1,
        'result_per_page' => $result_per_page
    ));
    $this->load->view('footer');
}

public function crpo_users() {

    $config = array();
    $config["base_url"] = base_url() . "tables/crpo_users";

    $table = 'cr        

Answers


Kenney February 2016

So, the problem is in:

function _prep_args($args) {
  // If there is no $args[0], skip this and treat as an associative array
  // This can happen if there is only a single key, for example this is passed to table->generate 
  // array(array('foo'=>'bar'))
  if (isset($args[0]) && count($args) === 1 && is_array($args[0]) && ! isset($args[0]['data'])) {
    $args = $args[0];
  }
  foreach ($args as $key => $val) {
    is_array($val) OR $args[$key] = array('data' => $val);
  }
  return $args;
}

If $args is not an array, but an stdClass, then that would explain the error you get. To find out where it's called from with the wrong argument, you could either add

if ( is_object( $args ) ) throw new Exception("Bug!");

or

if ( is_object( $args ) ) { echo "<pre>"; debug_print_backtrace(); echo "</pre>"; }

Post Status

Asked in February 2016
Viewed 3,131 times
Voted 10
Answered 1 times

Search




Leave an answer


Quote of the day: live life