Reputation: 6110
Is the proper way to make a few variables available to all my controllers to add a MY_Controller.php
file in my /application/libraries/
folder (shown in the docs here)?
I'm working in Kohana 2.3.4 and wondering if there are any better ways to do it, or is this the only recommended method?
Being new to OOP, can you link me to any examples?
I've heard the right answer is to add the vars to your $config[]
, trying to get more details.
Upvotes: 0
Views: 5016
Reputation: 41
How does this feel then:
[bootstrap.php]
Kohana::$config->attach(new Kohana_Config_File('global'));
And then, create a new file under application/config called global.php
In it, put (for example):
return (array ('MyFirstVar' => 'Is One',
'MySecondVar' => 'Is Two'));
Anywhere in your code, access these variables with
Kohana::config ('global.MyFirstVar');
As you can see, 'global.' is used to access these variables; the reason for that is that you attached the global.php config file at the beginning.
Was this what you meant? :-)
Upvotes: 2
Reputation: 3257
The proper way is to make a custom config file (application/config/foobar.php), and access the data with Kohana::config('foobar.key').
The code igniter way is completely wrong and inappropriate.
See http://docs.kohanaphp.com/core/kohana#methods_config
Upvotes: 6