[Catalyst] Best practice for database connections, where $c is not available?

Oliver Charles oliver.g.charles at googlemail.com
Wed Dec 31 15:37:13 GMT 2008


Hi,

This has hit me a few times, and I've just encountered it again, so I
thought it would be good to ask those wiser than I :)

There have been a few times where I could do with querying the
database (which I'd normally do through $c->model), but this is not
available. For example, I've added the option for users to specify how
to display dates on our website, through a variety of formats. I
thought the best way to do this, would be using a Template Toolkit
plugin:

    [% USE user_date %]
    The date is [% user_date.format(some_date) %].

However, this plugin needs to access the user preferences model
($c->model('UserPreference')->date_format($user)). Should I be
instantiating this model (the Catalyst model is a very lightweight
wrapper around a non-catalyst specific model) - or is there a better
option?

- Ollie



More information about the Catalyst mailing list