<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Builder extends CI_Controller {
private $uri_segment = 4;
private $per_page = 4;
private $num_links = 6;
private $model;
public function __construct()
{
parent::__construct();
// Your own constructor code
$this->load->library('parser');
$this->load->model($this->model);
//$this->model = $this->User;
}
public function get_start_row(){
return $this->uri->segment($this->uri_segment, 0);
}
public function get_total_row(){
return $this->model->count();
}
public function pagination($data){
$this->load->library('pagination');
$config['base_url'] = $data['url'];
$config['total_rows'] = $data['total_row'];
$config['per_page'] = $this->per_page;
$config['num_links'] = $this->num_links;
$config['uri_segment'] = $this->uri_segment;
$config['full_tag_open'] = '<div class="text-center"><ul class="pagination">';
$this->pagination->initialize($config);
return $this->pagination->create_links();
}
public function index() {
//$this->session->unset_userdata('_task');
//$this->session->unset_userdata('_value');
$start = $this->get_start_row();
$data['result_list'] = $this->model->get_list(array(), $start, $this->per_page);
$display_row = '';
if(empty($data['result_list'])){
$data['result_list'] = array(
array('user_id' => '','user_name' => '','user_tel' => '','user_email' => '',
'user_username' => '','user_password' => '','user_permission' => '')
);
$display_row = 'display:none';
}
$data['txt_search'] = '';
$data['pagination'] = '';
$data['display_list'] = $display_row;
$this->parser->parse('builder/user', $data);
}
public function save() {
$post = $this->input->post(NULL, TRUE); // returns all POST/GET items with XSS filter
$data = array(
'user_id' => $post['user_id(Primary)'],
'user_name' => $post['user_name'],
'user_tel' => $post['user_tel'],
'user_email' => $post['user_email'],
'user_username' => $post['user_username'],
'user_password' => $post['user_password'],
'user_permission' => $post['user_permission']
);
$this->model->id = $post['id'];
if($this->model->save($data)){
$result = array('result' => true);
}else{
$result = array(
'result' => false,
'message' => $this->db->error()
);
}
echo json_encode($result);
}
public function delete() {
$this->user->id = $this->input->post('id', true);
if($this->user->save($data)){
$result = array('result' => true);
}else{
$result = array(
'result' => false,
'message' => $this->db->error()
);
}
echo json_encode($result);
}
}
?>
遇到PHP错误
严重性:错误消息:呼叫成员 函数get_list()在非对象上的文件名:controllers / Builder.php
行号:46 Backtrace:
答案 0 :(得分:0)
问题出在你调用$this->load->model($this->model);
的构造函数中。当调用它时,类属性$model
没有值。所以你基本上称为$this->load->model(NULL);
,这是没有意义的,所以在范围内不会有一个叫做“模型”的对象。
你可能想要做更像$this->load->model('user_model');
的事情,或者,如果你坚持使用class属性,你必须先设置它。
public function __construct()
{
parent::__construct();
$this->load->library('parser');
$this->model = 'user_model';
$this->load->model($this->model);
}
或许我误解了你的意图。如果是这样,请告诉我们您的目标。