0

I have this function in my controller:

public function checkout(){
        $data['items'] = $this->cart_model->get_items();

        $this->load->view("templates/header");
        $this->load->view("cart/checkout", $data['items']);
    }

Inside the checkout view I try to use this variable:

<?php foreach($items as $k => $item){?>

But this results in an error:

Message: Undefined variable: items

Any suggestions on how to fix this?

2
  • Are you sure data['items'] is populated with the expected results. In your checkout try var_dump(data['items']) Commented May 1, 2020 at 9:34
  • 1
    Hi Sebastian, don't inject $data['items'], just use $this->load->view("cart/checkout", $data);, then on your view file, use $items, or as you would do normally, foreach ($items as $item) { // code here } Commented May 1, 2020 at 9:36

1 Answer 1

2

change this

$this->load->view("cart/checkout", $data['items']);

to this

$this->load->view("cart/checkout", $data);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.