Deprecated/0.10/YourConfigFile
Warning! This page has the following tags:
- This page is deprecated, and is only useful for developers using Agavi 0.10.
- This page exists for reference purposes only.
Your Config File Tutorial
Purpose
This tutorial should take you through the relatively simple process of creating a custom .ini file using the Agavi framework.
Process
Step 1: Create your .ini file
Create a file named myapp.ini in the webapp/config directory of your application. Fill it with something appropriate (.ini format!), for example:
[EMAIL] ADMIN = 'admin@example.com' JUNK = 'junk@example.com'
Step 2: Define a handler in config_handlers.ini
Edit the file config_handlers.ini in the webapp/config directory of your application. Add the following to the bottom of that file:
[config/myapp.ini] class = "DefineConfigHandler" param.prefix = "MYAPP_"
This tells Agavi how to handle our new config file. In this example, we're using the pre-existing DefineConfigHandler?, which defines constants based on the contents of an .ini file. We're also passing a parameter to the DefineConfigHandler?, in this case prefix = "MYAPP_", which tells it to prefix that string onto the newly created constants.
Step 3: Tell Agavi to use your new config file
Where you put the following block of code will vary. If the contents of your config file are needed at a very base level across your entire app, it may make the most sense to add the code to your www/index.php file (or wherever you're dispatching your Controller). In other cases, you may only need the contents available within a certain lib, in which case you could put the code in the initializer of that class, and save the hit to the filesystem until you really need to do it. In either case, you'll need a block of code similar to this somewhere in your app:
// +---------------------------------------+
// | LOAD UP OUR myapp.ini settings file |
// +---------------------------------------+
ConfigCache::import('config/myapp.ini');
At this point, Agavi has defined the following constants for you:
| constant | value |
| MYAPP_EMAIL_ADMIN | "admin@…" |
| MYAPP_EMAIL_JUNK | "junk@…" |
Conclusion
Hopefully this tutorial has given you a brief overview into creating a custom config file.

