0

A PHP Error was encountered Severity: Notice

Message: Undefined property: Showdata::$Data_Model

Filename: controllers/Showdata.php

Line Number: 23

Backtrace:

File: C:\xampp\htdocs\CURD\application\controllers\Showdata.php Line: 23 Function: _error_handler

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

An uncaught Exception was encountered Type: Error

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

Filename: C:\xampp\htdocs\CURD\application\controllers\Showdata.php

Line Number: 23

Backtrace:

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

controller

<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 
class Showdata extends CI_Controller {
   function __construct() {
       parent::__construct();
       #$this->load->helper('url');
       $this->load->model('data_model');
    }

    public function index(){
        $data['user_list'] = $this->Data_Model->Get_Data();
        $this->load->view('data_view', $data);
    }
}
?>

view

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>User Details</title>
</head>
<body>
    <h2> Simple Data Display </h2>
    <table width="600" border="1" cellpadding="5">
        <tr>
            <th scope="col">Id</th>
            <th scope="col">User Name</th>
            <th scope="col">Email</th>
            <th scope="col">Mobile</th>
            <th scope="col">Address</th>
        </tr>
        <?php foreach ($user_list as $u_key){ ?>
        <tr>
            <td><?php echo $u_key->id; ?></td>
            <td><?php echo $u_key->name; ?></td>
            <td><?php echo $u_key->email; ?></td>
            <td><?php echo $u_key->address; ?></td>
            <td><?php echo $u_key->mobile; ?></td>
        </tr>
        <?php }?>
    </table>
</body>
</html>
Ignacio Ara
  • 2,476
  • 2
  • 26
  • 37

2 Answers2

1

You have just spelling mistake.

Check as below that may help.

public function index()
{
     $data['user_list'] = $this->data_Model->Get_Data();  // Use data_model instead Data_model
     $this->load->view('data_view', $data);
}
Virb
  • 1,639
  • 1
  • 16
  • 25
0
   Please try this code it will help you. This is controller code

   class Test extends CI_Controller { 

     function __construct() { 
      parent::__construct(); 
      $this->load->helper('url'); 
      $this->load->database(); 
    } 

   public function view(){

     $this->load->model('Test_model');
     $stud_data = $this->Test_model->view();
     $data['data'] = $stud_data->result();
     $this->load->view('Display', $data); 
  }
 }

 This is view part

   <!DOCTYPE html> 
    <html lang = "en"> 
    <body> 
     <table>
       <tr>
        <th>Id</th>
        <th>Name</th>
         <th>Email</th>
        <th>Password</th>
        <th>Edit</th>
        <th>Delete</th>
      </tr>
      <?php
       foreach($data as $key){ ?>
      <tr>
       <td>
          <?php echo $key->id ?> 
       </td>
       <td>
          <?php echo $key->name ?> 
       </td>
       <td>
          <?php echo $key->email ?> 
       </td>
       <td>
          <?php echo $key->password ?> 
       </td>
       <td>
           <a href="#">Edit</a>
       </td>
       <td>
           <a href="#">Delete</a>
       </td>
     </tr>
      <?php } ?>
     </table>
    </body>
    </html>
Bijal Patel
  • 210
  • 1
  • 3