wunayou 发表于 2012-3-6 08:42:08

Trying to get property of non-object

这是模型

function get_cart($id)
        {
                $q=$this->db->get_where('product',array('id'=>$id));
                if($q->num_rows()>0)
                {
                foreach ($q->result()as $results)
                {
                       
                       
                $cart[]=$results;
                }
                        return $cart;
                }
               
        }
这是控制器
   function add ()   {              $cart = $this->Products_model->get_cart($this->input->post('id'));   $data = array         ('id' => $this->input->post('id'),   'qty' => $this->input->post('qty') ,   'qty2' => $this->input->post('qty2'),    'price' => $cart->price,        'name' => $cart->brand   );   $c=$this->cart->insert('data');

Message: Trying to get property of non-objectFilename: controllers/cart.phpLine Number: 34
           echo print_r($c);

lynn.wang 发表于 2012-3-6 10:07:52

兄弟 你忘记了这一句啊
$this->load->library('cart');
页: [1]
查看完整版本: Trying to get property of non-object