views:

64

answers:

4

I am new to Code Igniter and I wish to know if there is anything that works like MasterPages do on .NET.

Also i was wondering where should i keep my public files, like scripts, styles and images.

Greetings, and Thank you in Advance

A: 

I am not too familiar with .NET or CodeIgniter, but it appears the same functionality can be provided by judicious use of Views. The first sentence on that page says:

In fact, views can flexibly be embedded within other views (within other views, etc., etc.) if you need this type of hierarchy.

This seems like exactly what a MasterPage provides. And in fact, most PHP frameworks and templating systems provide the same features.

In answer to your second question, you may want to keep your scripts, styles, and images in separate folders off of the web root. I believe that URLs are relative to index.php, so keeping your resources near there would make them easier to refer to in your views. Another option is to take a look at the Asset Helper.

TNi
right now i am getting the functionality playing with views, but i wanted to know if there is something that actually solves the issue in a more smart and easy way.
GerManson
I'll admit I don't know the first thing about MasterPages and had to look them up. From what I've read, though, it seems that each content page needs to reference its MasterPage, which doesn't seem too different from loading a main view in every "content" controller. Correct me if I'm wrong.
TNi
http://msdn.microsoft.com/en-us/library/wtxbf3hh.aspx
GerManson
Thanks! That's the exact page I read. A content page seems to need at the top a directive like <%@ Page Language="VB" MasterPageFile="~/MasterPages/Master1.master" Title="Content Page" %>.
TNi
+2  A: 

I'm not sure that they have anything exactly like a master page. CodeIgniter is more of an MVC framework and uses views and controls to build up pages. If you're new to CodeIgniter, net.TutsPlus has a real good series of videos that goes into some depth about how to use the framework for different scenerios. Take a look under the section called "Catch Up" to see the list of videos.

Hope this helps out some and good luck in your project.

Chris
thank you for the link, i really appreciate it
GerManson
+2  A: 

Master views aren't built into the framework. To get a similar effect you can load the subview and pass that to the master view.

Controller :

class Items extends Controller
{
    function show($id)
    {
        $item = $this->item_model->get_item($id);

        // Load the subview
        $content = $this->load->view('item/show', array('item' => $item), true);

        // Pass to the master view
        $this->load->view('master_view', array('content' => $content));
    }
}

Master view :

<div id="header">
</div>
<div id="content">
    <?php echo $content; ?>
</div>
<div id="footer">
</div>

To answer your other question, I keep all Javascript scripts and CSS in directories in the root of my project.

Stephen Curran
this was exactly what i was looking for, thank you very much :)
GerManson