• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Array in model weirdness

#1
[eluser]Shodan[/eluser]
Hi guys,

Please excuse me, I'm relatively new to CI, although I've made a couple of site's based on it, I'm still fairly "green".

I've come across a weird situation involving an array in a model. I'm try to make a standard "shopping cart" (called a "quick quote" in this instance) comprising of one "Quick_quote_cart_model" object containing many "Quick_quote_item_model" objects.

The items are stored in an array called $cart_items which is a property of the "Quick_quote_cart_model" object.

Here's the relevant code snippets, first the "Quick_quote_cart_model":
Code:
class Quick_quote_cart_model extends model
{
    var $cart_items = Array();
    
    /**
    * Quick_quote_cart_model::Quick_quote_cart_model()
    *
    * @access     public
    * @since     Version 2.0
    */
    function Quick_quote_cart_model()
    {
        parent::Model();
    }
// ------------------------------------------------------------------------
    /**
    * Quick_quote_cart_model::add_item()
    *
    * @access     public
    * @since     Version 2.0
    * @param     $_item object A quick_quote_item_model object.
    */
    function Add_cart_item($_item)
    {
        $item_id = $this->Total_items()+1;
        
    [line 36]$this->cart_items[$item_id]         = new Quick_quote_item_model();
        $this->cart_items[$item_id]->product_id        = $_item->product_id;
        $this->cart_items[$item_id]->product_name    = $_item->product_name;
        $this->cart_items[$item_id]->product_code    = $_item->product_code;
        $this->cart_items[$item_id]->product_thumb    = $_item->product_thumb;
        $this->cart_items[$item_id]->item_engraved    = $_item->item_engraved;
        $this->cart_items[$item_id]->qty            = $_item->qty;
        $this->cart_items[$item_id]->logo_colours    = $_item->logo_colours;
        $this->cart_items[$item_id]->size        = $_item->size;        
    }
....
....
....

"Quick_quote_item_model":
Code:
class Quick_quote_item_model extends model
{
    var $product_id         = "";
    var $product_name        = "";
    var $product_code        = "";
    var $product_thumb        = "";
    var $item_engraved        = "";
    var $qty                = 1;
    var $logo_colours        = "";
    var $size                = "";
// ------------------------------------------------------------------------
    /**
    * Quick_quote_item_model::Quick_quote_item_model()
    *
    * @access     public
    * @since     Version 2.0
    * @param     $_product_id     integeger
    * @param     $_product_name     string
    * @param     $_product_code     string
    * @param     $_product_thumb string
    * @param     $_item_engraved string
    * @param     $_qty             integer
    * @param     $_logo_colours     string
    * @param     $_size             string                            
    */
    function Quick_quote_item_model()
    {
        parent::Model();
    }
// ------------------------------------------------------------------------
    /**
    * Quick_quote_item_model::Quick_quote_item_model()
    *
    * @access     public
    * @since     Version 2.0
    * @param     $_product_id     integeger
    * @param     $_product_name     string
    * @param     $_product_code     string
    * @param     $_product_thumb string
    * @param     $_item_engraved string
    * @param     $_qty             integer
    * @param     $_logo_colours     string
    * @param     $_size             string                            
    */
    function Init(
                $_product_id
                ,$_product_name
                ,$_product_code
                ,$_product_thumb
                ,$_item_engraved
                ,$_qty
                ,$_logo_colours
                ,$_size                                        
                )
    {
        $this->product_id       = $_product_id;
        $this->product_name    = $_product_name;
        $this->product_code    = $_product_code;
        $this->product_thumb    = $_product_thumb;
        $this->item_engraved    = $_item_engraved;
        $this->qty        = 1;
        $this->logo_colours    = $_qty;
        $this->size        = $_size;
    }
// ------------------------------------------------------------------------
}

and here's the controller code that adds the item:
Code:
class Quick_quote extends Controller {

  var $per_page = 20; // number of items to list per page
  var $_quick_quote_cart = false;

    function Quick_quote()
    {
        parent::Controller();
                ...
                ...
        $this->load->model("Quick_quote_cart_model");
        $this->load->model("Quick_quote_item_model");        
                ...
                ...
        ...
        // initialise a new cart object
        $this->_quick_quote_cart    = new Quick_quote_cart_model();
        ...
        ...
        ...

        function Add()
        {
        ...
        ...
        ...
        $cart_item = new Quick_quote_item_model();
    $cart_item->Init(
            $prod_details['prod_id']
            ,$prod_details['prod_name']
            ,$prod_details['prod_code']
            ,$prod_details['pic_thumb']
            ,$this->input->post("engraved")
            ,$this->input->post("qty")
            ,$this->input->post("logo_colours")
            ,$this->input->post("item_size")
            );
    $this->_quick_quote_cart->Add_cart_item($cart_item);

continued in next post...


Messages In This Thread
Array in model weirdness - by El Forum - 10-02-2007, 09:18 AM
Array in model weirdness - by El Forum - 10-02-2007, 09:18 AM
Array in model weirdness - by El Forum - 10-02-2007, 10:10 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.