Jump to content

Recommended Posts

Hi all

 

I have some code I'd like to re-factor

 

<?php

         $question_1   =  $form->getObject()->getQuestion1();
         $question_2   =  $form->getObject()->getQuestion2();
?>

<div class="admin">
    <div>
    <?php
                echo $form['question_1']->renderLabel();
                echo $question_1;
    ?>
    </div>
</div>

<div class="adminl">
    <div>
<?php
                echo $form['question_2']->renderLabel();
                $q2 = str_replace("-", '<br />',$question_2);
                echo $q2;
                ?>
   </div>
</div>

 

I'd preferably like some kind of for loop, that will just increment the _1, _2 values.

 

Can anyone offer some help?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/217839-refactoring-pt-2/
Share on other sites

You can go much further then your suggestion, something like:

 

foreach($questions as $question) {
    foreach($question->getPossibleAnswers() as $answer) {
        echo '<li>', $answer->getLabel(), ' ', $answer->render($question->getUniqueID()), '</li>';
    }
}

 

But depending on your requirements this design may become more complex.

Link to comment
https://forums.phpfreaks.com/topic/217839-refactoring-pt-2/#findComment-1130645
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.