[Catalyst] Lightweight error/messages reporting to templates
Paul Makepeace
paulm at paulm.com
Wed May 23 19:29:57 GMT 2007
I'm hoping there's a 'best practice' or common pattern for reporting
errors and messages to templates (not necessarily just forms).
I find myself doing stuff like,
my @errors; my @messages;
# ...
if ($some_err_condition) {
push @errors, "whoops";
} else {
$obj->update;
push @messages, $obj->name . " updated!";
}
# ...
$c->stash(messages => join "<br/>", @messages);
$c->stash(errors => join "<br/>", @errors);
Which is then tediously copy & pasted amongst controllers that do that
reporting.
And then my template says something like,
[% IF errors %]
<p class="error">[% errors %]</p>
[% END %]
[% IF messages %]
<p class="messages">[% messages %]</p>
[% END %]
At least with the template I have that as a MACRO I can call variously
but I'd at least like a way to have some kind of
context/controller-wide way of dealing with these errors & messages. I
don't quite understand Cat's object model well enough to do this
globally myself yet.
P
More information about the Catalyst
mailing list