Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
致命错误。无法在第256行的C:\xampp\htdocs\system\libraries\Table.php中将stdClass类型的对象用作数组_Php_Mysql_Codeigniter_Pagination - Fatal编程技术网

致命错误。无法在第256行的C:\xampp\htdocs\system\libraries\Table.php中将stdClass类型的对象用作数组

致命错误。无法在第256行的C:\xampp\htdocs\system\libraries\Table.php中将stdClass类型的对象用作数组,php,mysql,codeigniter,pagination,Php,Mysql,Codeigniter,Pagination,当我试图在同一个控制器中执行2个函数时,出现了这个错误。第一个可以正常工作,但是得到了错误 “致命的错误。无法将stdClass类型的对象用作中的数组 第256行的C:\xampp\htdocs\system\libraries\Table.php 控制器 <?phpif (!defined('BASEPATH')) exit('No direct script access allowed'); class tables extends CI_Controller { public f

当我试图在同一个控制器中执行2个函数时,出现了这个错误。第一个可以正常工作,但是得到了错误

“致命的错误。无法将stdClass类型的对象用作中的数组 第256行的C:\xampp\htdocs\system\libraries\Table.php

控制器

<?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 = 'crpo_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;

    $datatable2 = $this->mtables->fetch_data($result_per_page, $this->uri->segment(3), $table);


    $this->load->view('header');
    $this->load->view('crpo_table_view', array(
        'datatable2' => $datatable2,
        'result_per_page' => $result_per_page));
    $this->load->view('footer');
}
) 
?>
因此,问题在于:

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;
}
如果
$args
不是一个数组,而是一个
stdClass
,那么这将解释您得到的错误。要找出它是从哪里用错误的参数调用的,您可以添加

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

if(is_object($args)){echo”“;debug_print_backtrace();echo”“;}
这样就可以了:


哪一行代码给出了错误?只需在其中放入一个文件代码,删除所有其他文件,并通过一些注释或标记在系统文件中设置错误,在第256行
protectedfunction\u prep\args($args)上的C:\xampp\htdocs\Codeigniter\system\libraries\Table.php中说明错误所在的行{//如果没有$args[0],跳过此项并将其视为关联数组//如果只有一个键,则可能会发生这种情况,例如,这将传递到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)或$args[$key]=array($data'=>$val)}返回$args;}
第196行@KenneyThank。您找到在代码中调用它的位置了吗?如果扩展
CI_表
,您可以重写
受保护的函数_prep_args($args)
支持
stdClass
,否则可能一个
(数组)
强制转换就足够了。或者它可能只是一个简单的打字错误?我找不到错误,但在不使用表库生成表@kenneyAh时,它可以正常工作,这是一种规避问题的方法;-)好的,如果您尝试了我回答中的两个建议之一,并且得到了堆栈跟踪,那么如果您感兴趣的话,也许您可以将其添加到您的问题中,这样我们就可以找出哪里出了问题。它是否可以在像
echo$this->table->generate($datatable3);
这样的行上?查询的结果必须是result\u array()的格式,而不是result()@kenney请解释一下你的答案
<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>

<div id="wrapper">
<div id="page-wrapper">
    <div class="row">
        <div class="col-lg-12">
            <h1 class="page-header"> Users</h1>
            <ol class="breadcrumb">
                <li><a href="index.html">Dashboard</a></li>
                <li>View Users</li>
                <li class="active">Donors/Foster Parents</li>
            </ol>
        </div>
        <div class="col-lg-3 col-sm-offset-1">
            <a href="<?= base_url('users') ?>" class="btn btn-default">Department Officers</a>
        </div>
        <div class="col-lg-4">
            <a href="<?= base_url('crpo') ?>"class="btn btn-default">Child Rights Promoting Officers</a>
        </div>
        <div class="col-lg-4">
            <a href="<?= base_url('donors') ?>"class="btn btn-default active">Donors/ Foster Parents</a>
        </div>
    </div>
    <!-- pagination -->                
    <div>

        <?php
        // generate the table
        $this->table->set_heading('Fisrt name', 'Last name', 'Contact no','Address','Username', 'Email');
        echo $this->table->generate($datatable3);

        // generate the page navigation

        echo $this->pagination->create_links();
        ?>

    </div>



</div>
</div>
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 ( is_object( $args ) ) throw new Exception("Bug!");
if ( is_object( $args ) ) { echo "<pre>"; debug_print_backtrace(); echo "</pre>"; }
$sql = "SELECT * FROM users";
$stmt = $pdo->query($sql);
while( $res = $stmt->fetch(PDO::FETCH_ASSOC)){
     $res['row_name'];
};