0

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..

2
  • why $pages and not years ? Commented Jun 7, 2011 at 12:13
  • try var_dump($years); to see what inside $years Commented Jun 7, 2011 at 12:13

3 Answers 3

3

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.

Sign up to request clarification or add additional context in comments.

Comments

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

1 Comment

Yes this was a typo.. now I have it set to years and it actually doesn't fill the select box at all... so what am I missing?
0

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 .

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.