[Catalyst] Accessing $c from Model

Lorn lorn.br at gmail.com
Wed Dec 27 12:55:36 GMT 2006


you can passa the $c from controller to model
$c->model(foo)->bar($c,$foobar);

On 12/27/06, Mark Zealey <mark at itsolve.co.uk> wrote:
>
> Hi there,
>
> I'm basically wanting to write a simple log function which logs hits on my
> website as entries in a database (automatically adding $c->user->{id} and
> $c->req->referrer etc), but to do so I want to use a model (I think). Any
> ideas how I can just say $c->model('Log')->info("foo") and automatically
> get
> $c passed in? I think I could have sth like:
>
> package MyApp::Model::Log;
> use base 'Catalyst::Model';
>
> my $last_c;
>
> sub ACCEPT_CONTEXT {
>         my ($self, $c) =3D @_;
>         $last_c =3D $c;
> }
>
> sub info {
>         my ($self, $msg) =3D @_
>         my $c =3D $last_c;
>         ...
> }
>
> but this seems pretty messy...
>
> Mark
>
> _______________________________________________
> List: Catalyst at lists.rawmode.org
> Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
> Searchable archive:
> http://www.mail-archive.com/catalyst@lists.rawmode.org/
> Dev site: http://dev.catalyst.perl.org/
>



-- =

Lorn
- Slackware Linux
www.slackwarezine.com.br
- http://lornlab.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20061227/963fb=
3fe/attachment.htm


More information about the Catalyst mailing list