terrid25 Posted November 5, 2010 Share Posted November 5, 2010 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 More sharing options...
ignace Posted November 5, 2010 Share Posted November 5, 2010 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 More sharing options...
terrid25 Posted November 5, 2010 Author Share Posted November 5, 2010 Well that doesn't really help me. I just to loop through and possibly replace the _1, _2 with an incrementing value Link to comment https://forums.phpfreaks.com/topic/217839-refactoring-pt-2/#findComment-1130735 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.