[eluser]robnecciai[/eluser]
Please forgive me in advance. I know that similar topics have been covered in the forum. However, I'm new to CI and I'm struggling to find a good MVC way of handling views.
I know that standard information for headers and footers can easily be handled by extending MY_Controller. As I understand it, this will allow me to manage the output of the views and add a header, footer, etc. to each and optionally pass data to them for display.
However, I am having some difficulty with the main view in that each page in my site can have varying dynamic content that must be pulled from the database (Ads, for example). Some pages have ads and some do not. Moreover, the TYPE of ads displayed on one page may be different (size, content, etc.) than the type of ads displayed on others. I'm not sure I want to know all of that detail in the controller code.
My thought is to add code to each of the "main" views that instantiate and call library functions to get the desired content. Although, I think this may violate MVC practices. The solution would be something like this...
MY_Controller would combine the following when outputting every page
[header_view.php] - fairly static, passed variables for things like "greeting name", "logged-in", etc.
[????_view.php] - the "body", or main part of the page - passed variables for the main content and calls library functions to get the rest
[footer_view.php] - same functionality as header
By the way, I have a simple "storedcontent.php" library built in CI. This library basically accesses the database to return content based on a given "key". So, the "main" view may make a call to get content like this:
<div>
<?php
$this->CI =& get_instance();
$this->CI->load->library('storedcontent');
echo $this->CI->storedcontent->stored_content('TEST_CONTENT');
?>
</div>
It seems that this allows a little more flexibility when designing the views...
Is this acceptable or is there a better way?
Thanks, in advance,