[Catalyst] Configuring a Controller from the config file

Matt S Trout dbix-class at trout.me.uk
Fri Aug 1 01:01:52 BST 2008


On Wed, Jul 30, 2008 at 01:38:00PM +0200, Moritz Onken wrote:
> Hi,
> 
> I tried to set some config options for a controller with the config  
> file.
> 
> YAML-code:
> 
> ---
> name: MyApp
> 
> Controller::Root:
>   key: value
> 
> I'm using ConfigLoader and the debug shows that it successfully loaded  
> the yaml file.
> In a method in my Root controller I tried to access those config  
> options via $self->config.

Which contains the class-level defaults.

Not application defaults.

You should never, ever EVER access $self->config in a model, view or
controller object.

Your config value will be in $self->{key}.

It's considered normal to do

package My::Controller::Foo;

use strict;
use warnings;
use parent qw(Catalyst::Controller);

__PACKAGE__->mk_accessors(qw(foo bar));

__PACKAGE__->config(
  foo => 'default_for_foo',
  bae => { default => 'for_bar' },
);

then later in your code just call $self->foo to get the runtime value.

-- 
      Matt S Trout       Need help with your Catalyst or DBIx::Class project?
   Technical Director                    http://www.shadowcat.co.uk/catalyst/
 Shadowcat Systems Ltd.  Want a managed development or deployment platform?
http://chainsawblues.vox.com/            http://www.shadowcat.co.uk/servers/



More information about the Catalyst mailing list