I’m new to CodeIgniter and I hope that my question will have a simple answer.
I have a website with a couple of menu items (menuA,menuB and menuC).
I have modeled it with one main controller, index(), menuA(), menuB() and menuC() in the controller. The called function sets a session value currentMenu and includes header, X, footer. Where X depends on the function called. The header then high lights the choosen menu.
Within menuC (Account settings in my webapp) I would like to have a different controller that controls subviews of AccountSettings/NotLoggedIn.
Logically I would like menuC() to include the header and the footer but then forward the call to a subcontroller that managed login or the sub pages.
Am I using the framwork wrong or is there a straight forward way to achieve this?
I think it sounds like you’re not understanding how to apply MVC to your structure. Picture it this way:
Controllers represent some facet of your application that users can interact with. For example, I could have an
itemscontroller that allows users to create, read, update, or deleteitems. All the logic for interacting withitemsis handled by that controller (meaning it calls theitemsmodel and renders the necessary views).In your case it sounds like you are building a
pagescontroller that handles displaying the content for specific pages a user may call. So your controller could look something like this:Views can get a little tricky when you’re dealing with complex sites that have overlap. One of the most useful tricks I’ve discovered along the way is using a emplating library to reduce redundancy. This is the one I use all the time: http://williamsconcepts.com/ci/codeigniter/libraries/template/reference.html . Using the template library you can easily define a layout that includes your header and footer and then just pass in a partial for the content you want to display.
When you want to deal with logic in something like a menu, all you need to do is pass in a variable with the page name and then do some basic PHP render the menu.
Hope this helps!