Welcome Guest, Not a member yet? Register   Sign In
Template Variables
#1

[eluser]donkey_[/eluser]
Hi folks,


As I know it's possible to define variables for CodeIgniter HTML Views that's all okay but isn't there a possibility to save them global to access from every view or model or lib ?


kind regards - donkey
#2

[eluser]TheFuzzy0ne[/eluser]
Can you be more specific?

Variables should be generated on-the-fly, and passed in to the view. If you have some variables that should be the same everywhere, you can either put them into a config file, or perhaps a model which you will auto load on each call.

If you can give us an example of the variables you have in mind, someone may be able to give you a more direct answer.
#3

[eluser]donkey_[/eluser]
re folks,


well I think that it's ugly to define the variables spread in more files ... I think CI should have a Common file where you can Define or set Variables for the templates , that's what I mean ... do you understand me now?
#4

[eluser]TheFuzzy0ne[/eluser]
That's an ideal use for a model. CodeIgniter is built upon the MVC pattern, which helps keep the three major components of your projects separate. It also makes it possible to re-use your code.

Try not to forget that CodeIgniter is not supposed to be a CMS, it's simply a framework to help make your life easier. It's down to the developer how they use the framework. Some would put such variables in a config file, others may use a model, others might even use a library or a helper functions, it's really up to you. I, for one, am happy generating the variables I need when I need them. I feel it gives me more control over what's going on in my code, and more flexibility.

Generally, if the variable doesn't need to be changed dynamically, I'd recommend putting them in the config file, whereas if they need to be generated dynamically at run time, I'd use a model, but that's just my personal preference.

However, you still haven't mentioned any specific variables that you'd like to organise. You've only really given a general outline.
#5

[eluser]Colin Williams[/eluser]
Quote:I think CI should have a Common file where you can Define or set Variables for the templates
$this->load->vars(); Call it from your own parent controller, autoloaded library constructor, hook, etc., and your vars will be available in every view
#6

[eluser]TheFuzzy0ne[/eluser]
Thanks for pointing that out. I was totally unaware of that functionality.




Theme © iAndrew 2016 - Forum software by © MyBB