遇到PHP错误严重性:通知消息:未定义属性:Site :: $ site_model

时间:2014-07-20 09:29:23

标签: codeigniter

  

遇到PHP错误

     

严重性:注意

     

消息:未定义的属性:Site :: $ site_model

     

文件名:controllers / site.php

     

行号:13

     

站点控制器site.php   致命错误:在非对象中调用成员函数delete_row()   第13行的C:\ xampp \ htdocs \ login \ application \ controllers \ site.php

我的控制器 - > 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();
        }
    }
} 

我的型号 - &gt; 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;
    }
}

我的视图 - &gt; 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');?>

3 个答案:

答案 0 :(得分:1)

您似乎没有加载您的&#34;网站模型&#34;代码中的任何地方都可以执行以下操作:

  1. 在自动加载文件中自动加载。
  2. 使用此行$this->load->model('site_model');
  3. 可以找到更多信息here

答案 1 :(得分:0)

您需要在控制器中加载模型。

 class Site extends CI_Controller{
            function __construct(){
              parent::__construct();
              $this->is_logged_in();
              $this->load->model('site_model'); //Load site_model
             ........

答案 2 :(得分:0)

在某些情况下,当您不将表单数据提取到模型时会发生这种情况。尝试在模型中提取($ _POST),不要忘了正确加载模型。

P.s .:这是解决我的错误的方法