[email protected] wrote:
Where is a good place to put app-specific configuration, and how would this be accessed within code. Say, for example, the number of blog posts to show on a page...?


You can easily use app/config/settings.xml for (environment specific) 
application wide settings.

Example:

<configuration environment="production">
  <settings prefix="Example.">
    <setting name="enabled">true</setting>
    <setting name="EntriesPerPage">25</setting>
    <setting name="DefaultColor">green</setting>
  </settings>
</configuration>

Yey...
You then get values like this:

$entries_per_page = AgaviConfig::get('Example.EntriesPerPage', 
$default_in_case_not_defined);

Interesting...
In case you have some logging functionality in your application you could for example use 
something like the following to prevent logging based on the "core.use_logging" 
setting (e.g. false in production environment, true otherwise):

if (AgaviConfig::get('core.use_logging', false))
{
  $this->getContext()->getLoggerManager()->log(new 
AgaviLoggerMessage(strftime('[%Y-%m-%d %H:%M:%S]', time()).' '.get_class($this).': 
'.$msg), $log_level);
}

Settings can be defined globally and then be overwritten in lower sections. E.g. you 
define a default setting for something and then override this for environment 
"production" later on in settings.xml. So you have a different setting just for 
production while other environments remain untouched and get the global setting.

I'm not sure this method of logging on first impression is suitable for me and would probably think about sticking to my own methods. Unless I end up using this for developer-only logging, in which case most of what I see makes perfect sense. Is this what it was intended for? Not clear...
Another possibility would be to get config settings from your own XML files by 
using XPath/DOM and some Agavi classes:

<configuration environment="development">
  <some name="nested-setting">
    <ae:parameters>
      <aE:parameter name="value1">value1</ae:parameter>
      <ae:parameter name="value2">value2</ae:parameter>
    </ae:parameters>
  </some>
</configuration>

$doc = new AgaviXmlConfigDomDocument();
$doc->load(AgaviConfig::get('core.config_dir').'/your_settings.xml');
// ... XPath query or whatever etc.

or

$cfg = AgaviConfig::get('core.config_dir').'/your_setting.xml';
$config = include(AgaviConfigCache::checkConfig($cfg))$nested_something = 
$this->config['some']['nested-setting'];
$value1 = $nested_something['parameters']['value1'];
$value2 = $nested_something['parameters']['value2'];

Remember, that you can always set values programatically using:

AgaviConfig::set('some.setting', 'some_value');

as you can see in index.php or config.php of your application.

The practicality of this becomes unclear to me towards the end but hats off sterling effort.

Def one to keep for the sampe app and the sooner the update the better


_______________________________________________
users mailing list
[email protected]
http://lists.agavi.org/mailman/listinfo/users

Reply via email to