消息:未定义的属性:CI_Loader :: $ table

时间:2013-03-25 12:45:54

标签: php codeigniter

这是我的控制器..

class Customer extends CI_controller
{

public function __construct()
{
    parent::__construct();
    $this->load->model('Customer_model');
}
public function create()
{

        $this->load->helper('form');
        $this->load->library('form_validation');
    $this->form_validation->set_rules('name', 'Name', 'required');
    $this->form_validation->set_rules('address', 'Address', 'required');
    $this->form_validation->set_rules('office_phone', 'Phonenumber', 'required');
    $this->form_validation->set_rules('fax', 'Faxno.', 'required');
    $this->form_validation->set_rules('email', 'Mailaddress', 'required');

    $data = array(
        'name' => $this->input->post('name'),

        'address' => $this->input->post('address'),

        'phoneno' => $this->input->post('office_phone'),

        'fax' => $this->input->post('fax'),

        'email' => $this->input->post('email')
    );


    if ($this->form_validation->run() === FALSE)
    {
        $this->load->helper('url');
        $this->load->view('templates/header');  
        $this->load->view('master/customer',$data);
    }
    else
    {

        $this->Customer_model->register($data);
        $this->load->library('session');
       //$this->session->set_flashdata('message', 'New Contact has been added');
             //redirect(current_url());
        $this->load->helper('url');
        $this->load->view('templates/header');
        $this->load->view('templates/success');
    }
    $this->load->library('pagination');
     $this->load->library('table');



      // Config setup
    $config['base_url'] = base_url().'/customer/';
    $config['total_rows'] = 20;
    $config['per_page'] = 10;
    // I added this extra one to control the number of links to show up at each page.
    $config['num_links'] = 5;
    // Initialize
    $this->pagination->initialize($config);


      $data1 = $this->db->get('registration');
      $header = array('Name', 'Address', 'phoneno','fax','email');
       $this->table->set_heading($header);
       $this->load->view('master/customer',$data1);
       }
}

这是我的观点..

<div id='results'>
<?php  echo $this->table->generate($data1); ?>
<?php echo $this->pagination->create_links(); ?>
</div>

在运行iam时收到类似这样的错误消息

遇到PHP错误

  

严重性:注意

     

消息:未定义属性:CI_Loader :: $ table

     

文件名:master / Customer.php

     

行号:44

     

致命错误:在非对象中调用成员函数generate()   C:\ XAMPP \ htdocs中\ CodeIgniter_2.1.3 \应用\视图\主\ Customer.php   第44行

任何人都请告诉我这是什么问题。我是新的代码签名者..

5 个答案:

答案 0 :(得分:5)

在视图中,调用get_instance()以获取CodeIgniter实例。从那里,您可以访问对象的table属性,调用您需要的方法。

<div id='results'>
<?php $CI =& get_instance(); ?>
<?php echo $CI->table->generate($data1); ?>
<?php echo $CI->pagination->create_links(); ?>
</div>

答案 1 :(得分:0)

尝试在构造函数中加载table

public function __construct()
{
     parent::__construct();
     $this->load->model('Customer_model');
     $this->load->library('table');
}

如果它仍然给出相同的错误,则将此table库加载到自动加载文件中 像这样

$autoload['libraries'] = array('table');

希望这会有用

答案 2 :(得分:0)

我想推荐你:

<?php $CI =& get_instance(); ?>

在您的视图中使用$CI代替$this,看看它是否有效..

答案 3 :(得分:0)

只需要一行

$this->load->library('table');

答案 4 :(得分:0)

试试这个:

$autoload['libraries'] = array('database','session','table');