0
votes

I have this html partial for putting together a html option box and it works great when I know the number of html option boxes that I need to create.

Controller:

    $formView = new ViewModel();  
    $formView->setTemplate('bns/questionnaires/forms/simple_scale_radio_form');

    $optionView = new ViewModel(array('name'=>'name 1'));
    $optionView->setTemplate('bns/questionnaires/forms/options_personality_profile');
    $formView->addChild($optionView, 'option_0');

View:

    <?php echo $this['option_0'] ?>

But, now I'm building this html option box dynamically from the database and if I wish to do this, I'm thinking of using the following code

Controller:

$formView = new ViewModel(array('count'=>3));
$formView->setTemplate('bns/questionnaires/forms/simple_scale_radio_form');

    $optionView = new ViewModel(array('name'=>'name 1'));
    $optionView->setTemplate('bns/questionnaires/forms/options_personality_profile');
    $formView->addChild($optionView, 'option_0');

    $optionView = new ViewModel(array('name'=>'name 2'));
    $optionView->setTemplate('bns/questionnaires/forms/options_personality_profile');
    $formView->addChild($optionView, 'option_1');

    $optionView = new ViewModel(array('name'=>'name 3'));
    $optionView->setTemplate('bns/questionnaires/forms/options_personality_profile');
    $formView->addChild($optionView, 'option_2');

View:

<?php 
        for ( $i = 0; $i < $count; $i++) {
            echo $this['option_' . $i];
        }
?>

But, PHP will throw this error: Cannot use object of type Zend\View\Renderer\PhpRenderer as array

What are my options?

Thanks in advance!

Cheers,

Justin

1

1 Answers

0
votes

K, So, I think I was over complicating the situation. The alternative to use partial is using partialLoop:

http://framework.zend.com/manual/2.0/en/modules/zend.view.helpers.html#partial-helper

Cheers!

Justin