[Catalyst] Catalyst::Plugin::Authentication::Store::DBIC and config in auto

fayland fayland at gmail.com
Thu Mar 23 10:40:59 CET 2006


Brandon Black wrote:
> On 3/22/06, fayland <fayland at gmail.com> wrote:
>   
>> hi, all.
>> Since we use more than one database server, I need to connect database
>> in sub auto of Root.pm.
>> so I config the Catalyst::Plugin::Authentication::Store::DBIC after the
>> connect like this:
>>
>> sub auto : Private {
>>     my ( $self, $c ) = @_;
>>
>>     # connect db
>>     $c->forward('init');
>>
>>     use Data::Dumper;
>>
>> $c->log->debug(Dumper($c->config->{dbic}{geo}->resultset('User')->search({})->first));
>>     $c->config->{authentication}{dbic} = {
>>         user_class         => $c->config->{dbic}{geo}->resultset('User'),
>>         user_field         => 'username',
>>         password_field     => 'password',
>>     };
>>
>> the debug screen shows that ->resultset('User')->search({})->first
>> works. but the Catalyst::Plugin::Authentication::Store::DBIC complains :
>> |
>> Caught exception in Zorpia::Controller::User->login "Can't call method
>> "search" on an undefined value at
>>
>> any suggestion? can I config the DBIC in the auto?
>>
>> Thanks. any tip is appreciated very much.

OK, finally I get the solution. I just wonder whether it is the right 
answer:

package MyApp::Model::UserAuth;

use strict;
use warnings;
use base 'Catalyst::Model';

sub search {
    my $self = shift;
   
    my $user = MyApp->config->{dbic}{geo}->resultset('User')->search(@_);
   
    return $user;
}

1;

and config in the yml:

authentication:
  dbic:
    user_class: "MyApp::Model::UserAuth"
    user_field: "username"
    password_field: "password"

it seems works. please correct me if I'm doing something stupid. thanks.

-- 
Fayland Lam // http://www.fayland.org/ 




More information about the Catalyst mailing list