PHP消息:未定义属性:Update_form :: $ update_model

时间:2017-07-26 09:03:03

标签: codeigniter

请帮我解决这个错误:

遇到PHP错误

Severity: Notice

Message: Undefined property: Update_form::$update_model

Filename: controllers/update_form.php

Line Number: 15

Backtrace:

File: C:\xampp\htdocs\306\application\controllers\update_form.php
Line: 15
Function: _error_handler

File: C:\xampp\htdocs\306\index.php
Line: 315
Function: require_once

遇到未捕获的异常

Type: Error

Message: Call to a member function rest() on null

Filename: C:\xampp\htdocs\306\application\controllers\update_form.php

Line Number: 15

Backtrace:

File: C:\xampp\htdocs\306\index.php
Line: 315
Function: require_once

这是代码:

update.php

<?php
class Update extends CI_Controller
{
    function __construct()
    {
        parent::__construct();
        $this->load->helper(array('html','form','url'));
        $this->load->library('table');
        $this->load->model('update_model');
    }
    function index()
    {
        $this->table->set_heading('Books Name','Author','Edit Records');

        $tstyle= array(

                'table_open' => '<table border="1" align="center" cellpadding="4" cellspacing ="0">'
            );
        $this->table->set_template($tstyle);

        $answer = $this->update_model->select();

                foreach ($answer as $row)
                {
                    $link = anchor(base_url().'update_form/update_function/'.$row->id,'Edit');
                    $this->table->add_row($row->name,$row->author,$link);
                }
                echo $this->table->generate();
    }
}?>

update_model.php

<?php

/**
* 
*/
class Update_model extends CI_Model
{

    function __construct()
    {
        parent::__construct();
    }

    function select()
    {
        $this->db->select();
        $this->db->from('books');

        $query = $this->db->get();

        return $query->result();
    }


    function rest($id)
    {
        $this->db->select();
        $this->db->from('books');
        $this->db->where('id',$id);

        $query1= $this->db->get();
        if($query1->num_rows() ==1)
        {
            return $query1->result();

        }
    }
}?>

update_form.php

<?php

class Update_form extends CI_Controller
{
    function ___construct()
    {
        parent::__construct();
        $this->load->helper('form');
        $this->load->model('update_model');

    }

    function update_function($id)
    {
        $answer = $this->update_model->rest($id);

            foreach ($answer as $row) 
            {
                echo form_open();
                echo form_label('Book','book');
                echo form_input('book', $row->name);

                echo form_label('Author','author');
                echo form_input('author', $row->author);

                echo form_submit('submit','Update');
                echo form_close();


            }

    }

}?>

1 个答案:

答案 0 :(得分:0)

您需要逐行检查,我将在下面添加 控制器:

在控制器页面顶部添加以下行

 if ( ! defined('BASEPATH')) exit('No direct script access allowed');

**检查控制器类名称大写第一个字母。 **

$this->load->model('update_model');

现在update_model.php

  

添加:$ this-&gt; db-&gt; select('*')

尝试在方法上加载模型,或者您可以尝试检查autoload.php文件..

它在update_form.php上显示第15行: 在控制器中公开您的函数。

检查或标记已接受(如果有效)