0
votes

In Catalyst framework there is a global init sub(executed before any controller). i want the set some config variable from DB(like supper admin id or admin email for GPG configuration ).

i tried to use auto and 'begin' actions but those actions are just executed for its corresponding controller.

in Root.pm file:

sub auto :Private {
    my ($self, $c) = @_;

    my $config = $c->model('DB')->resultset('Config')->single();
    $c->config->{var1} = $config->var1;

};

When i request another controller like Controller2 and begin , the $c->config->{var1} was empty..

1
There does not appear to be a question here. - Len Jaffe
I think it's "How do I set a config variable from DB?", but that's pretty vague. It would help to know a bit more precisely what problem was encountered. - ikegami

1 Answers

1
votes

That sort of configuration belongs in the main program, i.e. MyApp.pm, so it is set before you even think about accepting a request. You don't normally want to be configuring database connectivity during every request cycle.

Your question isn't entirely clear, but if you do need to configure database settings on every request, then the auto sub in the root controller Root.pm would be the place to ensure it happened at the top of every request.

But I can't help feeling there's an X-Y problem in here...