Welcome Guest, Not a member yet? Register   Sign In
view structure
#1

[eluser]ToddyBoy[/eluser]
In my previous life of coding before I found CodeIgniter, I would use a lot of include statements for certain elements in a page, eg navigation, footer, etc. so I only had to change it once and have it applied to all pages with that file included.

Being new to MVC, I'm not sure how to go about doing something similar, especially when it comes to form validation and including snippets of code for stuff like blog post summaries, random testimonial quotes.

I've tried to use something like this in my controller

Code:
function index()
    {
        $data['query'] = $this->db->get('blog');
        
        $this->load->view('blog/blog_header');
        $this->load->view('blog/blog_excerpt', $data);
        $this->load->view('blog/blog_footer');
    }

What happens with form validation and recalling the same page with error messages? I tried doing the same as the example in the User Guide but it used one single view for the whole page whereas I use 3.

The other area I have trouble with is trying to get something like including a small snippet of code to display a random client testimonial, for example. In my previous life, I would use a PHP include statement and it would work. Would I do the same from inside the view that contains the content of the page or would I have a separate view for just the testimonial and place that above or below the content view?

An easy way to get around all of this would be to use a single view for each each 'page' but that seems to defeat the purpose of MVC and OOP.
#2

[eluser]jedd[/eluser]
Hi ToddyBoy,

Can I point you to the absolute last section on the [url="http://ellislab.com/codeigniter/user-guide/general/views.html"]CI User Guide's Views[/url] page.

I suspect utilising the feature of returning a view-loading into a variable, and then a 'main view' that just echo's the relevant variables you've now created, in whatever location within your overall page structure, will probably go some way to addressing your confusion here.

Oh, and then I'll point you at my usual couple of threads: [url="http://ellislab.com/forums/viewthread/109698/"]this one[/url] and also [url="http://ellislab.com/forums/viewthread/110969/"]this one[/url].




Theme © iAndrew 2016 - Forum software by © MyBB