Welcome Guest, Not a member yet? Register   Sign In
would like some help getting a model to work
#1

[eluser]Flying Fish[/eluser]
Thus far I've been just to db queries in my controller, but I'd like to start using models, as that seems to be a better practice.

Here's a rough model I'm using
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/*

    The Order model is used by the admin controller to display orders

*/


class Orders extends Model {

    function __construct()
    {
        // Call the Model constructor
        parent::Model();
    }
    
    function all_orders()
    {
        $query = $this->db->get('nbt_orders');
        return $query->result();
    }

    function new_orders()
    {
        $query = $this->db->get_where('nbt_orders', array('status' => 'ordered'));
        return $query->result();
    }

    function old_orders()
    {
        
        $query = $this->db->get('nbt_orders');
        return $query->result();
    }

}






/* End of file order_model.php */
/* Location: ./system/application/models/order_model.php */


Here's my controller
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/*

    The Admin class is where we can view and manage orders.

*/


class Admin extends Controller {

    function __construct()
    {
        parent::Controller();
        
        // Customize the tags that wrap arround the form validation error messages
        //$this->form_validation->set_error_delimiters('<div class="error">', '</div>');
        
        // Restrict access to Admins only
        if($this->authentication->check_admin() === TRUE)
        {
            return TRUE;
        } else
        {
            show_error('404');
        }
        
        $this->load->model('Orders');
    }
    
    function index()
    {
            
        $data['title'] = "Admin :: NBT Supplies";
        $data['heading'] = "Admin";
        //$data['query_new_orders'] = $this->db->get_where('nbt_orders', array('status' => 'ordered'));
        $data['query_new_orders'] = $this->Orders->new_orders();
        $data['query_orders'] = $this->db->get_where('nbt_orders', array('status' => 'printing', 'status' => 'shipping', 'status' => 'complete'));
                
        // Load this view by default
        $this->load->view('admin_index', $data);
    }
    
}


/* End of file admin.php */
/* Location: ./system/application/controllers/admin.php */

But I'm getting this error message.

Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined property: Admin::$Orders

Filename: controllers/admin.php

Line Number: 37

Fatal error: Call to a member function new_orders() on a non-object in /Applications/MAMP/htdocs/staging2/system/application/controllers/admin.php on line 37

Anyone know why this is happening? Thanks,


Messages In This Thread
would like some help getting a model to work - by El Forum - 03-29-2009, 08:55 PM
would like some help getting a model to work - by El Forum - 03-29-2009, 09:17 PM
would like some help getting a model to work - by El Forum - 03-29-2009, 09:45 PM
would like some help getting a model to work - by El Forum - 03-29-2009, 09:50 PM
would like some help getting a model to work - by El Forum - 03-29-2009, 11:23 PM
would like some help getting a model to work - by El Forum - 03-30-2009, 05:30 AM
would like some help getting a model to work - by El Forum - 03-30-2009, 08:36 AM
would like some help getting a model to work - by El Forum - 03-30-2009, 09:50 AM
would like some help getting a model to work - by El Forum - 03-30-2009, 09:55 AM



Theme © iAndrew 2016 - Forum software by © MyBB