Download - LinuxFocus

Transcript
Models
// Call the Model's parent constructor
parent::__construct();
}
// This method retrieves the products list and returns an array of
// objects each containing product details.
public function get_products()
{
// Calling the CI's db object's method for generating SQL
// queries.
$query = $this->db->get('products');
// returns an array of products objects
return $query->result();
}
// This method retrieves a specific product's details identified by
// $product_id as a parameter
public function get_product($product_id)
{
// Calling the CI's db object's methods for generating SQL
// queries.
$this->db->select('*');
$this->db->from('products');
$this->db->where('product_id', $product_id);
// Calling the CI's db object method for executing the query
$query = $this->db->get();
// Returning array of one object element containing product
// details.
return $query->result();
}
// This method adds a product to the products table Parameters
// $data - The data to insert into the table
public function addProduct($data)
{
// Calling the CI's db object method for inserting a product data
// into the products table.
$this->db->insert('products', $data);
}
// This method updates a product row in the products table
// parameters $product_id - The product id, $data - The updated
// data
public function updateProduct($product_id, $data)
{
// Calling the CI's db object's methods for generating SQL queries
$this->db->where('product_id', $product_id);
[ 130 ]