[eluser]zutis[/eluser]
This is how I would do it ... this way you should find it easier to add more tables (like order_products etc) in the future
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()
{
$this->db->from('nbt_orders');
$query = $this->db->get();
return $query->result();
}
// Can pass an array or a single staus as a string
function at_status($status='')
{
if(is_array($status))
{
$this->db->where_in('status', $status);
}
elseif($status !== '')
{
$this->db->where('status', $status);
}
return $this->all_orders();
}
function old_orders()
{
return $this->all_orders();
}
}
/* End of file order_model.php */
/* Location: ./system/application/models/order_model.php */
<?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_orders'] = $this->orders->at_status(array('status' => 'printing', 'status' => 'shipping', 'status' => 'complete'));
// Load this view by default
$this->load->view('admin_index', $data);
}
}