Welcome Guest, Not a member yet? Register   Sign In
Views or Nested Views or Base Controllers or all of the above :s
#1

[eluser]andychurchill[/eluser]
I'm getting frustrated as I know what I want, but I don't know what I'm doing, and now I'm getting in a muddle.

I originally started out calling $this->load->view() multiple times in my controllers, once to load the top of the page including opening html, meta, and navigation, etc, once for the main content, and then finally the footer, but having seen other projects, they use nested views instead, and make sure that each view is valid html in it's own right, with self contained elements with no orphan closing or opening tags. The problem I had with this approach was that each view would open the html tags, define meta data, and only then would it include the nested view for the main body content. This meant that it's still repeating the same links to css or js on multiple views, which again seems the wrong way to do it.

I feel like the best way to structure my pages is to have one view which contains the opening and closing html tags, then a nested meta block, common navigation, the main body of the page as another nested view which is passed in, and the static footer. Then in each controller I'd set the meta data for the header view, and the view and data required to populate the main nested view.

It's also looking likely that every page will need access to a certain library, which means I'd have to set it in each controller. At this point it sounds like I need to create a base controller that inherits from CI_Controller, which defines the basic variables required to build a page (title, description, keywords, account details) and then have all my pages inherit from this controller, which will override the page meta data, and only really need to set up the nested view for the main content of the page.

I'm trying to find an up to date tutorial on this kind of approach as it seems like a logical way to do it, but perhaps I'm just used to Master pages in ASP.NET Big Grin
#2

[eluser]Nick_MyShuitings[/eluser]
This is the answer to both of your wishes:

https://bitbucket.org/jamierumbelow/code...roller.php

You owe me cookies now Smile
#3

[eluser]andychurchill[/eluser]
Cheers, this has been a great help, spent last night restructuring all the views and controllers in my project and now everything feels clean and right. I can get back to working on actual features now instead of moving files and code around like I've been doing for the past two nights Big Grin




Theme © iAndrew 2016 - Forum software by © MyBB