Where to place general global variables? |
[eluser]Ki[/eluser]
Further note: if you do decide to create the variables in a config/model/library, you would have to load them in every controller in order to reference them. This may be a little bit difficult to maintain in the long run.
[eluser]chefnelone[/eluser]
[quote author="samota" date="1266802447"][quote author="chefnelone" date="1266802139"][quote author="samota" date="1266715168"]I don't mean to be repeating what I mentioned earlier, but if you load info from database, why don't you use My_controller to load everything you need for every page? It seems to be the common solution judging by the posts...[/quote] I think that since a controller can't be autoloaded it isn't a good option for what I need. I need the variables available everytime/everypage.[/quote] If you create My_controller, will just extend it every page instead of the Controller. This way you do not have to load library/model in every controller. Best of luck![/quote] I think now I see what you mean, Can you leave me a link to a post/wiki that show me how to create My_controller thanks
[eluser]Ki[/eluser]
it is VERY easy... I have mentioned this solution to you because I deeply believe it will be the best match for your needs as I had same issue. and there is NO WIKI needed. It is built into CI! In your system/application/libraries create a file called MY_Controller.php. It will look like this: Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); The above library will allow you to controll everythign you need for ALL of your site in one location. To use it in your controllers simply Code: <?php And in all controller you end up extending My_controller, which loads all of CI stuff in Controller + anything you define to load in My_controller Let me know if you need more help
[eluser]chefnelone[/eluser]
[quote author="samota" date="1266803971"]it is VERY easy... I have mentioned this solution to you because I deeply believe it will be the best match for your needs as I had same issue. and there is NO WIKI needed. It is built into CI! In your system/application/libraries create a file called MY_Controller.php. It will look like this: Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); The above library will allow you to controll everythign you need for ALL of your site in one location. To use it in your controllers simply Code: <?php And in all controller you end up extending My_controller, which loads all of CI stuff in Controller + anything you define to load in My_controller Let me know if you need more help[/quote] many thanks samota. I'll go for your suggestion.. Just one more question. It seems to me that using hooks is not recommended. Why is that?
[eluser]Ki[/eluser]
Hooks are great if you want to "hack" CI permanently. My_controller allows you to ADD to CI + gives you the flexibility to change everything you want any time you want. If you build your My_controller into most of your controller, you know that whenever you need to change something globally, you have one place to do that. I personally see hooks as a little bit more 'hidden' solution. I use hooks when I have a deleted page or method and I want to permanently (forever) redirect users to another page. And generally, My_controller is easier to manage and maintain because it ends up being the core of your website if you construct it properly.
[eluser]chefnelone[/eluser]
[quote author="samota" date="1266805189"]Hooks are great if you want to "hack" CI permanently. My_controller allows you to ADD to CI + gives you the flexibility to change everything you want any time you want. If you build your My_controller into most of your controller, you know that whenever you need to change something globally, you have one place to do that. I personally see hooks as a little bit more 'hidden' solution. I use hooks when I have a deleted page or method and I want to permanently (forever) redirect users to another page. And generally, My_controller is easier to manage and maintain because it ends up being the core of your website if you construct it properly.[/quote] Thanks for the explanation. ;-) |
Welcome Guest, Not a member yet? Register Sign In |