Set global variables for all controllers in Kohana 2.3.4

Is the right way to make several variables available to all of my controllers in order to add a file MY_Controller.phpto my folder /application/libraries/( shown in docs here )?

I work in Kohana 2.3.4 and wonder if there are any better ways to do this, or is this the only recommended method?

Being new to OOP, can you please connect me with any examples?

I heard that the correct answer is to add vars to yours $config[], trying to get more details.

0
source share
2 answers

- (application/config/foobar.php) Kohana:: config ('foobar.key').

.

. http://docs.kohanaphp.com/core/kohana#methods_config

+6

:

[bootstrap.php]

Kohana::$config->attach(new Kohana_Config_File('global'));

application/config global.php

():

return (array ('MyFirstVar' => 'Is One',
               'MySecondVar' => 'Is Two'));

Kohana::config ('global.MyFirstVar');

, "". ; , global.php.

?: -)

+2

Source: https://habr.com/ru/post/1743067/


All Articles