Welcome Guest, Not a member yet? Register   Sign In
CI 2.0 update now code isn't working
#1

[eluser]minerbog[/eluser]
Afternoon all,

I have just updated to CI2.0 and the code I had working in 1.7.3 no longer works. The error I'm getting is:
Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined property: Customers::$db

Filename: core/Model.php

Line Number: 50

The code is as follows:
Customer Controller
Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Customers extends CI_Controller {

    function __construct()
    {
        parent::__construct();
        $this->output->enable_profiler(TRUE);
        //$this->load->library('login');
        $this->load->model(array('Common','Customers_model'));
    }
    
    function index () {
        $this->listall();
    }
    
    function listall() {
        $data['html'] = $this->Customers_model->get_customer_list();

        $this->load->view('global/header');
        $this->load->view('customers/customer_list_view',$data);
        $this->load->view('global/footer');
    }
}
Customer Model
Code:
<?php
Class Customers_model extends CI_Model {
    
    function __construct() {
        parent::__construct();
    }

    function get_customer_list() {
        $sql = "SELECT * FROM customers";
        $query = $this->db->query($sql);
        $html = '';
        if( ! $query->num_rows()>0)
        {
            $html .= '<tr><td class="item12">No Records Found</td></tr>';
        } else {
            foreach($query->result() as $row)
            {
            $html .= '
            <tr>
                <td class="item1">'.anchor('customers/edit/'.$row->customer_id, $row->customer_id).'</td>
                <td class="item4">'.$row->company_name.'</td>
                <td class="item1">&nbsp;</td>
                <td class="item1">&nbsp;</td>
                <td class="item3">'.$row->tel.'</td>
                <td class="item2">&nbsp;</td>
            </tr>
            ';    
            }    
        }
        return $html;
    }
}
Customer List View
Code:
<div id="content">
&lt;?php include APPPATH.'views/customers/customer_menu.php'; ?&gt;

<h1>Customer List</h1>
<table>
    <tr>
        <th class="item1">ID Number</th>
        <th class="item4">Company Name</th>
        <th class="item1">Owed</th>
        <th class="item1">Due</th>
        <th class="item3">Telephone</th>
        <th class="item2">Options</th>
    </tr>

    &lt;?php echo $html; ?&gt;
</table>
</div>

I have updated all the constructors to __construct and extended to the new CI_{some controller or model} but can't get it to work??

Any Ideas?

Many Thanks,

Gavin.
#2

[eluser]Frank Rocco[/eluser]
I would try changing:
Code:
$this->load->model(array('Common','Customers_model'));
to
$this->load->model('Common');
$this->load->model('Customers_model');
#3

[eluser]runemedia[/eluser]
I'm a CI noob, but perhaps this would help: https://bitbucket.org/ellislab/codeignit...when-using
#4

[eluser]bubbafoley[/eluser]
loading the models with an array shouldn't cause a problem.

Are you sure that the database is loaded?
#5

[eluser]minerbog[/eluser]
O dear, how embarrassing is this!!!
Quote:loading the models with an array shouldn’t cause a problem.

Are you sure that the database is loaded?
babbafoley, you where spot on. I forgot to update the config/autoload.php file to load the database class!!

DOH DOH DOH DOH DOH SLAP!!!!!
#6

[eluser]InsiteFX[/eluser]
Controlller is now CI_Controller

Model is now CI_Model

InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB