foreach语句的php数组问题(代码点火器)

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 far I noticed that the $years is empty and the getYears is not being called.. no idea why yet..

<select>
    <?php foreach ($years as $row):?>
        <option><?=$row?></option>
    <?php endforeach;?>
</select>

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.

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 .