According to the manual and my code, this should be working perfect, but it is not. I’ve been messing around with this code for too long, and I wanted anyone to look at it to see if there is something I cannot see.
I am trying to call the index() action of my plans controller passing an array of data to the element for display. Anyone know why this is not working?
I am getting common error:
Notice (8): Undefined variable:
plans [APP/views/elements/search_dental_plans_results.ctp, line 12]
Warning (2): Invalid argument supplied for foreach()
[APP/views/elements/search_dental_plans_results.ctp, line 12]
And here is my code:
home.ctp
<?php echo $this->element('search_dental_plans_results'); ?>
views/elements/search_dental_plans_results.ctp
<h2>Plans List</h2>
<?php $plans = $this->requestAction('plans/index'); ?>
<?php foreach($plans as $plan): ?>
<ol>
<li><?php echo $plan['Plan']['id']; ?></li>
</ol>
<?php endforeach; ?>
controllers/plans_controller.php
function index() {
//$plans = $this->paginate();
if (isset($this->params['requested'])) {
return $plans;
} else {
$this->set('plans', $plans);
}
}
I SOLVED this in an “unexpected” way (at least according to the manual this method was not noted):
element
…
…
controller logic
Works like a charm : ) although I am going to use a containable and cache control when done, but at least its working as expected.
Not too holy and problem solved : )