It is very interesting the way you did. Could you show us some code examples here?
In my case, my layout could looks like:
Main view:
+-------------------------------------------------------------+
| HTML HEADER |
| Page Title |
+-------------------------------------------------------------+
| HTML BODY |
| +---------------------------------------------------------+ |
| | Container | |
| | +-----------------------------------------------------+ | |
| | | HEADER | | |
| | | Logomark, Menu, Search Field, Login Status, etc. | | |
| | +----------------+----------------------+-------------+ | |
| | | Left Side | Center Contents | Right Side | | |
| | | | | | | |
| | | +------------+ | +------------------+ | +---------+ | | |
| | | | Sub-Menu | | | Product Offers | | | Banners | | | |
| | | +------------+ | +------------------+ | +---------+ | | |
| | | | Product | | | News | | | Stats | | | |
| | | | Categories | | +------------------+ | +---------+ | | |
| | | +------------+ | | Top Selling | | | Links | | | |
| | | | Top Brands | | | Products | | | or Tags | | | |
| | | +------------+ | +------------------+ | +---------+ | | |
| | +----------------+----------------------+-------------+ | |
| | | FOOTER | | |
| | +-----------------------------------------------------+ | |
| +---------------------------------------------------------+ |
+-------------------------------------------------------------+
First, I don’t want to break the HTML of my Main View into pieces for the header, the contents and the footer. I don’t want to have invalid HTML code in my views, with unclosed tags and things like that.
The Header don’t change too much. Only a few information, like Login Status or the last user search may change on it. The Footer also do not change often. But it may contain the current date, the used memory and the elapsed time.
The Left Side, Center and Right Side changes a lot. They may change in every page request and also changes if the user is logged in or not.
“Sub-menu”, “Product Categories”, “Top Brands”, “Product Offers”, “News”, “Top Selling Products”, “Banners”, “Stats” and “Links or Tags” are modules of my application. They could be sub_controllers with their own views and models. It do not need to load directly by the URI, but the user could pass information to them by the URI. As for example, which sub_controller function will executed and what parameters will be passed.
What I need is to find a way to load them inside my Main View, without to build every module first in arrays, every time, within my requested controllers, and after pass them to the Main View. The only thing I would like to do is to specify in the requested controller which sub_controllers I want to load and they will do the job themselves. The loaded sub_controllers could be executed, and return all processed data to the requested controller, which will send it to the Main View.
I know that I can do this using libraries. But how can i do this without manually load the views and build everything in arrays in each controller and each controller’s function? I think a Nested MVC is the best answer to my pray. Isn’t it?
Also I need to change the Page Title accordingly. This can be done by the requested controller.
The layout above apply to the Home, but in sub pages it may not have the Right Side and modules change in each sub page. For example, in the Product Details sub page, it will display other modules, related to the product selected by the user.
In the old days I was used to simple use INCLUDE(‘file.php’) or, in the case of dynamic content, just use INCLUDE($file.’.php’). Everything else was automatically done by PHP. The templates did load other PHP scripts, which in turn did load another templates or PHP scripts and so on. All I needed before was to specify what will be inside of what. Now, what is the best practice with CI to achieve the same, without a Nested MVC?