Global Includes? |
[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
[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.
[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
[eluser]Bramme[/eluser]
The solution Brandon Dickson brings in this topic could be off value to you too!
[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
[eluser]xwero[/eluser]
I would use the Template inheritance helper this keeps it all in the view files where it is supposed to be.
|
Welcome Guest, Not a member yet? Register Sign In |