CodeIgniter Forums
Code Separation - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Code Separation (/showthread.php?tid=8749)

Pages: 1 2


Code Separation - El Forum - 05-29-2008

[eluser]phybertek[/eluser]
Hello,

I've used scaffolding to design an application for my site. It is great for adding testing data, but now I am moving to the user and administration phase. I'm looking into building form inputs. I have one question about this process. How are people seperating code and html with in their projects for forms.

I understand the process of controllers and views, but how are people in the CI world keeping their views clean for html designers and their Controllers doing all of the logic?

Can someone share an example of one of their controllers or models with form building kept seperated? Or, where can I get this information from. I was looking into pagination, but I can not figure out how to keep all of that out of my view.

Phybertek


Code Separation - El Forum - 05-29-2008

[eluser]adwin[/eluser]
I use smarty extension. It keep your code clean .... Wink

please look at the wiki to know more about how to implement smarty with ci Wink

about pagination ... you might use flexigrid (it has ci component as well), you can search about flexigrid in this form or go to this page http://webplicity.net/flexigrid/

ps: I use smarty, freakauth, and flexigrid component for my development. because I dont want to mess up my designer html


Code Separation - El Forum - 05-29-2008

[eluser]phybertek[/eluser]
Adwin,

I'll check these out. Thank you for the direction.

Regards,

-Phybertek


Code Separation - El Forum - 05-29-2008

[eluser]phybertek[/eluser]
So, basically, there is not way in native CI to separate code logic from the presentation layer? What is the view for really?

Pt


Code Separation - El Forum - 05-29-2008

[eluser]Majd Taby[/eluser]
take a look at CodeExtinguisher (links in my signature)


Code Separation - El Forum - 05-30-2008

[eluser]Lone[/eluser]
phybertek: CI does keep the code logic seperate from the view as long as you program it that way. What you do from your controller is send a set of variables to the view from which the designer can use from there on.

IMO using smarty templates is just another layer that isn't needed - it is well worth a designer knowing some very simple PHP eg. a foreach loop and variable output. Below is quick sample:

CONTROLLER
Code:
function view_product() {
  $data['product'] = $this->Product->get_product($id);
  $data['images'] = $this->Product->get_images($id);
  $this->load->view('view_product',$data);
}

VIEW
Code:
<? $this->load->view('header'); ?>

<h1>&lt;?=$product['title'];?&gt;</h1>
<p>&lt;?=$product['description'];?&gt;</p>

<div id="images">
&lt;? foreach ($images as $image) { ?&gt;
  <img src="&lt;?=$image['file'];?&gt;" alt="" />
&lt;? } ?&gt;
</div>
&lt;? $this->load->view('footer'); ?&gt;



Code Separation - El Forum - 05-30-2008

[eluser]xwero[/eluser]
To add to Lone's response you could use php's alternative syntax then you can write the foreach as
Code:
&lt;? foreach ($images as $image): ?&gt;
  <img src="&lt;?=$image['file'];?&gt;" alt="" />
&lt;? endforeach ?&gt;
Other controller structures have a similar alternative syntax.


Code Separation - El Forum - 05-30-2008

[eluser]Michael Wales[/eluser]
Quote:So, basically, there is not way in native CI to separate code logic from the presentation layer? What is the view for really?

There is not a native way to pull CI's scaffolding out - no. You would develop your own administrative logic and views.


Code Separation - El Forum - 05-30-2008

[eluser]adwin[/eluser]
I prefer to add additional layer because smarty is very usable for me. I don't like to mix my php code with html ... so messy Wink


Code Separation - El Forum - 05-30-2008

[eluser]phybertek[/eluser]
Adwin,

I'm with you on that. Php programming and HTML works from opposite sides of the brain. If you happen to find an HTML designer that knows PHP, the cost goes up. I like to keep them always separate to keep cost down.

Phybertek