消息:未定义属性:CI_Loader :: $ table [英] Message: Undefined property: CI_Loader::$table

查看:564
本文介绍了消息:未定义属性:CI_Loader :: $ table的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的控制器。

  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-& > post('email')
);


if($ this-> form_validation-> run()=== FALSE)
{
$ this-> load-> ('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 ['base_url'] = base_url()。'/ customer /';
$ config ['total_rows'] = 20;
$ config ['per_page'] = 10;
//我添加了这个额外的一个来控制显示在每个页面上的链接数。
$ config ['num_links'] = 5;
//初始化
$ 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\\\\\\\\\\\\\

任何机构请告诉我什么是problem.i是新的codeignator ..

解决方案

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

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


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

A PHP Error was encountered

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

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

解决方案

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

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

这篇关于消息:未定义属性:CI_Loader :: $ table的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆