• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Clean up my view

#1
[eluser]johnwbaxter[/eluser]
I would really like to get this sort of stuff out of my view

Code:
<?php foreach($con_options->result() as $item):?>
    <?$checkbox_value = $item->contact;?>
    &lt;?=form_checkbox('parent_contact[]', $checkbox_value, FALSE)?&gt;<label for ='&lt;?=$item->contact;?&gt;'>&lt;?=$item->contact;?&gt;</label><br />
    &lt;?php endforeach;?&gt;

and into a controller. I'm not averse to using the CI template syntax but i really cant figure out how to do it.

Any ideas?

#2
[eluser]Michael Wales[/eluser]
You kind of want that sort of stuff in your view.
I mean, you could add this into your controller, but it's going to suck trying to manage:

Code:
&lt;?php foreach ($con_options->result() as $item) {
$data['sucky_large_block_to_echo'] .= '&lt;input type=\"checkbox\" name=\"parent_contact[]\" value=\"" . $item-&gt;contact . "\"><label for=\"" . $item->contact . "\">" . $item->contact . "</label><br />";
}

Then in your view:
Code:
&lt;?= $sucky_large_block_to_echo; ?&gt;

That's really abusing the system though and you may as well move to one large file, dropping the MVC framework altogether.

#3
[eluser]johnwbaxter[/eluser]
I thought that might be the case. As long as i'm not doing it the stupid way then i don't mind!

Having a look through Oscar Bajner's sample files at his Obsession lib has given me some excellent pointers for getting some more stuff out of the view and into the controller though.

I recommend having a peruse!


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.