Code Separation


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.


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

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


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



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


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

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:

function view_product() {
  $data['product'] = $this->Product->get_product($id);
  $data['images'] = $this->Product->get_images($id);

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


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

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

[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.

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


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.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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