![]() |
How to separate the code from [controller] into [view]? - 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: How to separate the code from [controller] into [view]? (/showthread.php?tid=56465) |
How to separate the code from [controller] into [view]? - El Forum - 12-21-2012 [eluser]chiquitta[/eluser] I am new in Codeigniter! I use PHPexcel to upload , read and insert data to my database but i don't know how to use [view] i only use [model] and [controller] i cant understand how to separate the code into [view]. so I did a stupid way to deal with, but it's very ugly without any css. please help me! Code: function read() How to separate the code from [controller] into [view]? - El Forum - 12-21-2012 [eluser]CroNiX[/eluser] Basically the view is any html and what is needed to generate the final output. You pass variables to the view using an array with key/value pairs. The key will become the variable in the view. Here's an simple example just using straight variables. Normally you'd be retrieving these from the database, etc., but you'd assign them to the array the same way by setting a key that then gets accessed in the view. //controller Code: function display() The view /application/views/your_view.php Code: //output the page title in a div Now all of your HTML is separate from your controller, and appears as pure html (instead of echoing php strings as html). The controller only gathers data, like from models, to pass to the view but doesn't have anything directly to do with the HTML output. That's all contained separately in views. You can also load multiple views. Like one view can contain the header information, another one contain the body (the part that will most likely change from page to page) and another contain the footer. Then you just load them in order to create the full page. |