views:

530

answers:

2

EDIT: Kohana 2.3.4

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)?

Are there any better ways to do it, or is this the only recommended method?

Being new to OOP, can you link me to any examples?

EDIT 2:

I've heard the right answer is to add the vars to your $config[], trying to get more details.

+1  A: 

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%5Fconfig

zombor
A: 

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? :-)

joho