Working with Addons/Modules/Views
Creating an instance of an application object is done by invoking the object's class constructor (either explicitly or implicity) Beside allocating memory for the new object, the constructor will generally also initialize some of the object attributes. Alternatively, this can be done by a separate init method that should be called before the instance can be safely used. Since some objects have lots of different options, it is generally desired that these attributes have a default initialization value which will save the developer the burden of providing them for each new instance.
toKernel offers the possibility of taking advantage of its configuration file support to set these default values as it best suits your needs without having to edit and change the application code itself.
You can have as many configuration files as you like in the config directory, but the framework needs to have a least one present.
See INI class library to see how to use other config files.
The required minimal contents of an addon config.ini configuration file is:
[CORE] version=1.0.0 Alpha allow_cli=0 allow_http=1
The 'allow_cli' parameter let you specify is you want to allow the addon to be used in CLI mode or not by respectively setting it to 1 or 0.
In our example, running the addon in cli mode will not be allowed.
See Running an application in CLI mode for a discussion of how to run the application in CLI mode.
The 'allow_http' parameter let you specify is you want to allow the addon to be used in HTTP mode or not by respectively setting it to 1 or 0.
In our example, running the addon in http mode is allowed and you can invoke the suitable methods from a browser.See Running an application in HTTP mode for a discussion of how to run the application in HTTP mode.
In addition to these parameters required by the framework itself, you are free to invent and add any other parameter that is useful for your application.
Reading the values of parameters in the config.ini file is done through a call to $this->config().
will return the value of the "allow_cli" parameter.
Of course, you may add other sections to the config.ini file to keep things organized. This is done by merely adding a section name between square brackets on a line of its own:
To access the parameter value, just call the config method as follow:
$value = $this->config('my_param', 'My_section');