[Catalyst] C::C::FormBuilder debug noise...
Marcello Romani
mromani at ottotecnica.com
Mon May 7 10:55:59 GMT 2007
RA Jones ha scritto:
> Marcello Romani wrote:
>> RA Jones ha scritto:
>>> It looks like your output is showing both debug1 and debug2 levels,
>>> which suggests your fb config settings are not being used. Did you place
>>
>> That's what I thought too.
>>
>> Where do you put the "debug" option ?
>>
>> I tried this:
>>
>> package MyApp::Controller::FBConfig;
>>
>> use strict;
>> use warnings;
>>
>> use base qw/Catalyst::Controlloer::FormBuilder/;
>>
>> sub new {
>> my $class = shift;
>> my $self = $class->SUPER::new(@_);
>> $self->{debug} = 0;
>> return 0;
>> }
>>
>> 1;
>>
>> But of course it doesn't work. Could you post (some of) your code ?
>>
>> Thanks you very much.
>>
> As I indicated previously, I have a sub-class of CCF containing
> formbuilder configuration settings (and more) which is a parent class
> for all my (formbuilder-using) controllers. So:
>
> package MyApp::Controller::ClassThatUsesFormBuilder;
>
> use lib '/path/to/my/perl-lib';
> use base qw/My::Formbuilder/; # configures CCF;
>
> sub build_form : Local Form('/users') {
> my ($self, $c) = @_;
>
> my $form = $self->build_user_form($c); # in My::Formbuilder
>
> # etc;
> }
>
> package My::Formbuilder;
>
> use base qw/Catalyst::Controller::FormBuilder/;
>
> __PACKAGE__->config(
> 'Controller::FormBuilder' => {
> new => {
> debug => 0,
> # ^^^^^^^^^^ debug settings here
> messages => {
> # override default messages go here,
> },
> validate => {
> # complex validation routines here
> }
> }
> stash_name => 'fb', # ie fb.field.some_field.value in TT
> },
> );
>
> sub build_user_form {
> my ($self, $c) = @_;
>
> my $form = $self->formbuilder;
>
> # fields requiring complexity not available to .fb source file:
> $form->field(
> name => 'some_field',
> options => [
> map [ $_->id, $_->location ],
> $c->model('Schema::Location')->search({},
> { order_by => 'location'} )
> ],
> );
>
> return $form;
> }
>
> Not only does this work, but I find it more convenient specifying
> formbuilder config options in one place rather than in every controller
> that uses CCF. Hope it works for you.
Damn, it works!!
I'll re-read the docs, but I think they just mention the
__PACKAGE__->config(
'Controller::FormBuilder' => {
new => {
debug => 0,
},
},
);
bit, but don't tell you where to put it.
It puzzles me somewhat that putting that bit of code in MyApp.pm nothing
would happen...
Thank you.
--
Marcello Romani
Responsabile IT
Ottotecnica s.r.l.
http://www.ottotecnica.com
More information about the Catalyst
mailing list