Currently I have
private function getYears()
{
return array('Test1', 'Test2', 'Test3', 'Test4');
}
in the index:
$years = $this->getYears();
and in the view
<select>
<?php foreach ($years as $row):?>
<option><?=$row?></option>
<?php endforeach;?>
</select>
The select box doesn't get filled ?
How can I fix this ?
[edit]
So fa开发者_JAVA技巧r I noticed that the $years is empty and the getYears is not being called.. no idea why yet..
I don't know what you're iterating over.
You've passed the values to $years
, yet you're iterating over $pages
. Is that a typo?
In any case, you're iterating over an array of arrays. Do a var_dump on the $row
variable and check what you're actually iterating over.
<select>
<?php foreach ($years as $row):?>
<option><?=$row?></option>
<?php endforeach;?>
</select>
Not advisable iteration, it is better to iterate in the controller and use view to create get html tags and just pass the data to the main view .
精彩评论