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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15615319/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 09:37:05  来源:igfitidea点击:

Message: Undefined property: CI_Loader::$table

phpcodeigniter

提问by Rag

this is my controller ..

这是我的控制器..

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);
       }
}

This is my view part..

这是我的观点部分..

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

while running iam getting an error message like this

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

A PHP Error was encountered

遇到 PHP 错误

Severity: Notice

Message: Undefined property: CI_Loader::$table

Filename: master/Customer.php

Line Number: 44

Fatal error: Call to a member function generate() on a non-object in C:\xampp\htdocs\CodeIgniter_2.1.3\application\views\master\Customer.php on line 44

严重性:注意

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

文件名:master/Customer.php

行号:44

致命错误:在第 44 行调用 C:\xampp\htdocs\CodeIgniter_2.1.3\application\views\master\Customer.php 中非对象的成员函数 generate()

Any body please tell me what is the problem.i am new to codeignator..

任何机构请告诉我有什么问题。我是 codeignator 的新手。

回答by Kemal Fadillah

When in the view, call get_instance()to get the CodeIgniter instance. From there, you can access the tableproperty of the object, call the method you need.

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

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

回答by Azam Alvi

Try to load tablelibrary in your constructior

尝试table在您的构造函数中加载库

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

if it still give same error then load this tablelibrary into autoload file like this

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

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

hope this will work

希望这会奏效

回答by Mohammed Sufian

i would like to recommend you this:

我想向你推荐这个:

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

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

use $CIinstead of $thisin your view, and see it is working or not..

使用$CI而不是$this在您看来,看看它是否有效..

回答by uniquecode1

only one line your needed

只有一行您需要

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

回答by karthik karthi

Try this:

尝试这个:

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