Reputation: 1138
I'm looping over a set of products like this
<?php foreach ($results as $result): ?>
<?php echo $this->element('result_item', array('product', $result)); ?>
<?php endforeach; ?>
and here's an excerpt of my element code:
[...]
<?php echo $this->Html->url(array('controller' => 'view', 'action' => 'index', $product['Product']['product_slug'])) ?>
[...]
I'm getting the following error each I try to access $product
Notice (8): Undefined variable: product [APP/View/Elements/result_item.ctp, line 2]/view">
What am I doing wrong?
Upvotes: 0
Views: 715
Reputation: 289
Use array to pass variables to element.
See doc here: http://book.cakephp.org/2.0/en/views.html#passing-variables-into-an-element
Upvotes: 0
Reputation: 1378
You're passing through two arguments, instead of one named argument.
Change your view code to be this:
<?php foreach ($results as $result): ?>
<?php echo $this->element('result_item', array('product' => $result)); ?>
<?php endforeach; ?>
(Note the => instead of , in the element call)
Upvotes: 1