【发布时间】:2016-05-16 17:57:00
【问题描述】:
当我尝试在同一个控制器中执行 2 个函数时出现此错误。第一个工作正常,但得到错误
'致命错误。不能使用 stdClass 类型的对象作为数组 C:\xampp\htdocs\system\libraries\Table.php 在第 256 行。
控制器
<?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'] = ' <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(' ', $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'] = ' <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');
}
)
?>
型号
<?php
class mtables extends CI_Model {
function __construct() {
parent::__construct();
}
// Count all record of table "contact_info" in database.
public function record_count($table) {
return $this->db->count_all("$table");
}
// Fetch data according to per_page limit.
public function fetch_data($limit,$start,$table) {
$this->db->limit($limit, $start*$limit);
$query = $this->db->get("$table");
if ($query->num_rows() > 0) {
foreach ($query->result() as $row) {
$data[] = $row;
}
return $data;
}
return false;
}
}?>
查看 1 crpo_table_view.php
<?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">Child Rights Promoting Officer</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 active">Child Rights Promoting Officers</a>
</div>
<div class="col-lg-4">
<a href="<?= base_url('donors') ?>"class="btn btn-default">Donors/ Foster Parents</a>
</div>
</div>
<!-- pagination -->
<div>
<?php
// generate the table
$this->table->set_heading('Fisrt name', 'Last name', 'Contact no','Username', 'Email','Official Address','DS Division','District');
echo $this->table->generate($datatable2);
// generate the page navigation
echo $this->pagination->create_links();
?>
</div>
</div>
</div>
查看 2 donor_table_view.php
<?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>
【问题讨论】:
-
哪一行代码出错了?
-
只需将出错的文件代码放入其中,删除所有其他文件,并通过注释或标记说明出错的行
-
在系统文件中获取错误,C:\xampp\htdocs\Codeigniter\system\libraries\Table.php 位于第 256 行
protected 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; } -
@Kenney 中的第 196 行
标签: php mysql codeigniter pagination