How to accomplish this - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: How to accomplish this (/showthread.php?tid=40716) |
How to accomplish this - El Forum - 04-16-2011 [eluser]jfenety[/eluser] How can I accomplish this problem without repeating a bunch of code. I have a view, header.php that is loaded from the controller $this->load->view(header.php) for each page that needs the header. Example, I have three controllers, one for main, one for about, and one for contact. The code has to be in each of these. I want to have a Welcome, user at the top of the screen. I am using tank auth, in the controller I call isloggedin and then pass the username to the view from the controller. Is there a way I can do this without having to put this statement into every controller that needs the header.php? Could I call the tank auth library from the view, and get the user name in the view? Or would this introduce problems, or ruin the MVC architecture? Jfenety How to accomplish this - El Forum - 04-16-2011 [eluser]InsiteFX[/eluser] Create a template_view.php Code: <?php echo $this->load->view('header_view);?> In your Controller you can do this: Code: $data = array() InsiteFX How to accomplish this - El Forum - 04-16-2011 [eluser]jfenety[/eluser] Thanks for your help, Should I create a base_controller that all my other controllers inherit from? That way, I would just have the welcome message code in the base_controller, and then would never have to repeat it? How to accomplish this - El Forum - 04-16-2011 [eluser]InsiteFX[/eluser] Yes, that would be the way to go! Code: // MY_Controller - application/core/MY_Controller.php Admin_Controller - for backend Dashboard etc. Public_Controller - for frontend. InsiteFX How to accomplish this - El Forum - 04-16-2011 [eluser]jfenety[/eluser] Thanks a lot, I am working on a site similar to kijiji, but for only a specific need and for a specific market base. Its sort of a pet project, to learn php better. This gives me a great start to understand the code igniter framework, and to tinker away for a while in php. jfenety. |