![]() |
Dynamic Footer problem - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html) +--- Thread: Dynamic Footer problem (/thread-11286.html) |
Dynamic Footer problem - El Forum - 09-02-2008 [eluser]iainco[/eluser] Hey guys, currently making a project that is based on sports news, with users being able to rate articles and so on. The footer for each page will display articles that users have archived, top rated articles, tags for the current sport and a little search form. This footer is used on all pages. The problem arises where users who have not registered visit a publicly accessible page - (for example the 'About' page) Footer view code Code: <? if($this->session->userdata('email')): ?> Code for making the footer content available. Code: function __construct() But it means I need to have this code on every page... and I just can't think of a better way to overcome this problem. If I haven't explained the problem well please let me know and I will try to elaborate. Thanks Dynamic Footer problem - El Forum - 09-02-2008 [eluser]missionsix[/eluser] I've had a similar problem. All my pages are wrapped with similar header / footers. So calling those views on every controller page seemed like a lot of code duplication. So what I did was create a Parent controller that all my other controllers would extend. Then I created 1 method called Display that would load the header / footer views, or any other 'global' view files and then spit everything out into a container view. Example: Public_Controller.php Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); And then in my other controllers I do something like this: Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); Dynamic Footer problem - El Forum - 09-02-2008 [eluser]iainco[/eluser] Thanks for your reply, this looks like my solution ![]() Dynamic Footer problem - El Forum - 09-02-2008 [eluser]missionsix[/eluser] Your welcome! There is probably a better way to do it so you don't have to include the file in every controller, but its a lot less code duplication. I've also edited my post to reference the display method in the example controller to complete the example. Dynamic Footer problem - El Forum - 09-02-2008 [eluser]Colin Williams[/eluser] Quote:There is probably a better way to do it so you don’t have to include the file in every controller Create the parent controller in application/libraries/MY_Controller.php CodeIgniter will expect that it's an extension to the controller library and load it automatically But to the main question raised, and I'm not saying extending the controller won't work, this is partly the reason I developed the Template library, and why so many others have written and distributed similar solutions. If you approach output handling as being the sole responsibility of the given controller method, you're going to run into this problem over and over again. What Template does is allow the given controller method access to modify and control the ultimate output, while also providing access to any other component running for the given request (a library, a hook, etc.) In this way, your app is more flexible with regards to what is output. |