[Catalyst] Accessing $c from Model

Mark Zealey mark at itsolve.co.uk
Wed Dec 27 12:08:42 GMT 2006


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) = @_;
	$last_c = $c;
}

sub info {
	my ($self, $msg) = @_
	my $c = $last_c;
	...
}

but this seems pretty messy...

Mark



More information about the Catalyst mailing list