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



请帮助我解决此错误:

遇到 PHP 错误

Severity: Notice
Message: Undefined property: Update_form::$update_model
Filename: controllers/update_form.php
Line Number: 15
Backtrace:
File: C:xampphtdocs306applicationcontrollersupdate_form.php
Line: 15
Function: _error_handler
File: C:xampphtdocs306index.php
Line: 315
Function: require_once

遇到未捕获的异常

Type: Error
Message: Call to a member function rest() on null
Filename: C:xampphtdocs306applicationcontrollersupdate_form.php
Line Number: 15
Backtrace:
File: C:xampphtdocs306index.php
Line: 315
Function: require_once

这是代码:

更新.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();

}
}
}?>

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

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

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

**检查控制器类名大写首字母。 **

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

现在update_model.php

添加 : $this->db->select('*'(

尝试在方法上加载模型,也可以尝试检查自动加载.php文件。

它在update_form.php上显示第 15 行: 在控制器中创建函数公共。

检查或标记已接受是否有效

最新更新