Welcome Guest, Not a member yet? Register   Sign In
Pass data to a partial inside a loop

(06-21-2020, 04:46 AM)nneves Wrote: Hi

This is the first time I'm using CI and I have a questiona about getting data inside a partial within a loop.

On the controller I call the view with an array of data:

PHP Code:
return view('numero'$data); 

In the main view I have:

PHP Code:
<?php foreach ($items as $item) : ?>

<?= $item['id']; ?>

<?= $this->include('partials/item'?>

<?php endif ?>

In the partial I have:
PHP Code:
<?= $item['name']; ?>

and I get an error saying "Undefined variable: item"

How am I able to make this work?

Hello !
This question has already been answered in the user manual. Carefully study the code blocks that were provided as an example, especially pay attention to the block with the code that is called in the view itself on line No. 9, here's the record:
PHP Code:
<?php foreach ($todo_list as $item):?>
in any case, look carefully at how your keys are named in the $ data array. If memory serves me right and you want to iterate over the entire $data array, then you just need to specify this variable instead of your $item.
Read the:

p.s. I have not coded for a long time and therefore I can be mistaken in my last sentence.

P.S. Sorry my English.
I would change this world, but God doesn't give me the source.

Messages In This Thread
Pass data to a partial inside a loop - by nneves - 06-21-2020, 04:46 AM
RE: Pass data to a partial inside a loop - by Digital_Wolf - 06-21-2020, 11:20 AM

Theme © iAndrew 2016 - Forum software by © MyBB