<?php
class Cart extends CI_Controller{
public $paypal_data = '';
public $tax;
public $shipping;
public $total =0;
public $grand_total;
//cart index
public function index(){
//load view
$data('main_content') = 'cart';
$this->load->view('layouts/main', $data);
}//end function
//add to Cart
public function add(){
//item data in a array construct
$data = array('id'=> $this->input->post('item_number'), 'qty'=> $this->input->post('qty'), 'price'=> $this->input->post('price'), 'name'=> $this->input->post('title'));//end statement
}//end function
}//end class cart
The above code causes error as follows:"Fatal error: Cant' use function return value in write context". I looked and searched many time at the above code but just can not seem to find the error. I would greatly appreciate it if someone can help.
The problem is this line:
$data('main_content') = 'cart';
Using parentheses means you're calling a function, but you can't assign to a function call. You probably meant to assign to an array index, but you have no $data
array. I see you've created $data
in the add()
function, but that variable is local to that function. They probably both should be class properties, so they should be $this->data
. And in index()
you need to use square brackets.
public function index(){
//load view
$this->data['main_content'] = 'cart';
$this->load->view('layouts/main', $this->data);
}//end function
//add to Cart
public function add(){
//item data in a array construct
$this->data = array('id'=> $this->input->post('item_number'), 'qty'=> $this->input->post('qty'), 'price'=> $this->input->post('price'), 'name'=> $this->input->post('title'));//end statement
}//end function
May error in this line
$data = array();
$data['main_content'] = 'cart';