EllisLab released the latest version of CodeIgniter on January 30th. They've made plenty of improvements and bug fixes, and you can check out the changelog on their site. I've been using CodeIgniter for projects at work for about six months and I love it. It's made my code much more organized and easy to modify. If you aren't using CodeIgniter, or some other kind of PHP framework, I suggest you try it out. It's lightweight, easy to learn, and the documentation is fantastic.
One feature that I've always wanted is multiple views. Most web sites are split up into chunks like the header, sidebar, main content and footer areas. With regular PHP, you'd just do a require() to load the part you want, but with CodeIgniter it always felt a bit messy doing that.
Now if you want to load multiple views, you can do the following:
That's a great improvement, but today I was working on something where I want to have the loader return the view instead of render it right away. I loaded up the code for the loader and found out that it's already there. I didn't see it mentioned in the wonderful user guide, but I tried it out and it works great. So if you want to load a view but have it return the view as a string instead of rendering it, all you have to do is:
I'll be using this all of the time now. It's a great feature that just makes sense a lot of the time.

I'm Dan Previte, a web developer and a geek in general living in Chicago and working for




Hey man, great article, i may ask u something, iam really new in ci, iam wonderin if u can show, that entire controller file. iam come to use template for posicion .. here i dont understand how positionar, the views in the page.
txs for advance, good work!
–
sry about my english
Peter
February 8th, 2008
No problem, here’s an example controller class for a blog. You can comment on that post if you have other questions. You should also check out the CodeIgniter documentation if you haven’t.
dprevite
February 13th, 2008
I have discovered that you can have a view call other views, so my controllers only call one view which in turn calls the header, footer, and content.
I have the controller pass path of the particular content view it needs.
Based on your example, the controller:
$data['links'] = $this->_load_links();
$data['content'] = $this->_load_content();
$data['content_view'] = 'content/mycontent';
$this->load->vars($data);
$this->load->view('container');
Container view (container.php) loads header, footer, and content page:
$this->load->view('header');
$this->load->view($content_view);// loads the file at 'views/content/mycontent.php'
$this->load->view('footer');
Content view (/content/mycontent.php):
this is the content section of the page where we display the controller's output:
It might be a bit to complex for simple apps but it helps if you want to add/remove a view, like a sidebar for your entire site.
Natebot
April 9th, 2008
hmmm, looks like final section got stripped of my php tag. I’ll try html characters to display it:
Content view (/content/mycontent.php):
this is the content section of the page where we display the controller's output: >?=$content?<
Natebot
April 9th, 2008
whoop! Ok here is the whole thing correctly formatted!
Content view (/content/mycontent.php):
<p>this is the content section of the page where we display the controller's output: <?=$content?>
</p>
It might be a bit to complex for simple apps but it helps if you want to add/remove a view, like a sidebar for your entire site
Natebot
April 9th, 2008
I’ve tried it and it works, now I can use blocks in my websites.
Thanks!
kuve
August 7th, 2008
how can i use database values in html tables ?
Naushad
March 9th, 2009