遇到PHP错误严重性:通知消息:未定义的属性:Site :: $ site_model [英] A PHP Error was encountered Severity: Notice Message: Undefined property: Site::$site_model
问题描述
遇到PHP错误
A PHP Error was encountered
严重性:通知
消息:未定义的属性:Site :: $ site_model
Message: Undefined property: Site::$site_model
文件名:controllers / site.php
Filename: controllers/site.php
行号:13
站点控制器site.php
致命错误:在
中的非对象上调用成员函数delete_row()C:\xampp\第13行上的 htdocs\login\application\controllers onsite.php
Site Controller site.php Fatal error: Call to a member function delete_row() on a non-object in C:\xampp\htdocs\login\application\controllers\site.php on line 13
我的 controller >-> Site.php
My controller->Site.php
<?php
class Site extends CI_Controller{
function __construct(){
parent::__construct();
$this->is_logged_in();
}
function delete(){
$this->site_model->delete_row();
$this->index();
}
function members_area(){
$this->load->model('patient_model');
$data['records'] = $this->patient_model->getAll();
$this->load->view('members_area', $data);
}
function add(){
$data['main_content'] = 'patient_form';
$this->load->view('includes/template',$data);
}
function is_logged_in(){
$is_logged_in = $this->session->userdata('is_logged_in');
if(!isset($is_logged_in) || $is_logged_in != true){
echo 'Your don\'t have permission to access this page. <a href="../login">Login</a>';
die();
}
}
}
我的模型-> site_model.php
My model -> site_model.php
class Site_model extends CI_Model{
function get_records(){
$query = $this->db->get('patient');
return $query->result();
}
function delete_row(){
$this->db->where('id', $this->uri->segment(3));
$this->db->delete('patient');
}
function create_member(){
$new_member_insert_data = array(
'fname' => $this->input->post('fname'),
'lname' => $this->input->post('lname'),
'email' => $this->input->post('email'),
'address' => $this->input->post('address'),
'contact' => $this->input->post('contact'),
'remarks' => $this->input->post('remarks')
);
$insert = $this->db->insert('patient', $new_member_insert_data);
return $insert;
}
}
我的视图-> member_area.php
My view-> members_area.php
<?php $this->load->view('includes/header');?>
<div id="main">
Welcome Back, <u><?php echo $this->session->userdata('username'); ?>!</u>
<h3>Vision Eye Medical Center Patient Information</h3>
<div id="overflow">
<table class="features-table">
<thead>
<tr>
<td>Patient Name</td>
<td>Email</td>
<td>Address</td>
<td>Contact</td>
<td>Remarks</td>
<td>Action</td>
</tr>
</thead>
<tfoot>
<tr>
<td></td>
<td>-</td>
<td>-</td>
<td>-</td>
<td>-</td>
<td>-</td>
</tr>
</tfoot>
<tbody>
<?php foreach($records as $row): ?>
<tr>
<td><?php echo $row->fname;?>
<?php echo $row->lname;?>
</td>
<td><?php echo $row->email;?></td>
<td><?php echo $row->address;?></td>
<td><?php echo $row->contact;?></td>
<td><?php echo $row->remarks;?></td>
<td>View|<?php echo anchor("site/delete/$row->id",'delete');?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php echo form_open();?>
<?php echo anchor('patient/add', 'Add new Data'); ?><?php echo anchor('login/logout', 'Logout'); ?><br>
<?php echo form_close();?>
</div>
<?php $this->load->view('includes/footer');?>
推荐答案
似乎您没有加载站点模型您可以在代码中的任何位置执行以下操作:
It seems you are not loading your "site model" anywhere in code you can do following:
- 将其自动加载到自动加载文件中。
- 加载模型在控制器的构造函数中,或者使用此行在需要时加载
$ this-> load-> model('site_model');
- autoload it in autoload file.
- load your model either in constructor of controller, or load it whenever needed by using this line
$this->load->model('site_model');
更多信息,请参见此处。
这篇关于遇到PHP错误严重性:通知消息:未定义的属性:Site :: $ site_model的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!