Jump to content

Refactoring (PT 2)


terrid25

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

Archived

This topic is now archived and is closed to further replies.

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