Global Includes? - 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: Global Includes? (/showthread.php?tid=8865) |
Global Includes? - El Forum - 06-03-2008 [eluser]SplashCreativity[/eluser] Hey everyone, I'm not new to MVC frameworks though I am relatively new to codeignitor. What can I say, I love it! I have an issue though, I have my welcome controller for the first page, which goes something like this: Code: function index() As you can see I am using the form helper in my header, this is because the header page has a box which asks users to login (shown on each page) unless they are logged in it will show a menu. My issue is, I don't want to have to place the 17 lines for that login form on every controller / controller function I make. That would suck, instead I'm wondering is there no easy way of including the form helper stuff on every controller by default? Best Regards Stephen Global Includes? - El Forum - 06-03-2008 [eluser]stuffradio[/eluser] An easy way would be to make a helper with this code in it... make it so all you have to do is load the helper and maybe execute the function. Global Includes? - El Forum - 06-03-2008 [eluser]SplashCreativity[/eluser] That worked perfectly, just for anybody who doesn't understand and may be experiencing the same problem. 1. I created a new file: /system/application/helpers/login_helper.php 2. Added the code for the file in a function. Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 3. I edited my autoload.php to include the helper 'login' 4. In my controller I used the code Code: $header = get_form(); Take notice of the get_form (because I returned the $header variable in my function, it added the variables to my $header variable in my controller) Thank you very much stuffradio Regards Stephen Global Includes? - El Forum - 06-03-2008 [eluser]stuffradio[/eluser] Glad to help Global Includes? - El Forum - 06-04-2008 [eluser]Bramme[/eluser] The solution Brandon Dickson brings in this topic could be off value to you too! Global Includes? - El Forum - 06-04-2008 [eluser]Skulls[/eluser] helpers are made for flexibility functions... the $header stuff i see there is static... you should throw that $header information in a config and then set to autoload the config file or load the config where you need it the config file: Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); and then in the controller you have (after the config file is autoloaded or manualy loaded) Code: $header = $this->config->item('header'); in conclusion, you already have the config functions to get and store the static information.. so it makes no sense to make a helper for something already built Global Includes? - El Forum - 06-04-2008 [eluser]xwero[/eluser] I would use the Template inheritance helper this keeps it all in the view files where it is supposed to be. Global Includes? - El Forum - 06-04-2008 [eluser]GSV Sleeper Service[/eluser] onclick?! ugh... nasty |