[Catalyst] More new shortcuts
Sebastian Riedel
sri at oook.de
Sun Nov 6 21:05:22 CET 2005
Am 06.11.2005 um 20:46 schrieb Jules Bean:
> Sebastian Riedel wrote:
>> Small usability improvement today, we've just added $c-
>> >controller, $c->model and $c->view as shortcuts for $c->component.
>>
>> Examples:
>>
>> $c->model('DBIC::FooTable')->find(1);
>> $c->model('Xapian')->search(...);
>> $c->forward( $c->view('TT') );
>> [% FOR result = c.model('DBIC::BarTable')->search(...) %]
>
> Am I not right in thinking that this will only work if the
> component inherits from Catalyst::Base or at least one of its new
> friends? It's only for them that the automatic instantation in
> Setup occurs?
It works for all components that inherit from a Catalyst::Component
subclass, which are Catalyst::Base and the new Catalyst::Controller,
Catalyst::Model, Catalyst::View.
> I think there's a real potential source of confusion here. For
> example, a classic catalyst view or controller is typically a
> singleton object, and one can get away with confusing class and
> unique instance. However, a CDBI or DBIC model doesn't work like
> this: an instance represents a tuple (row if you prefer) in the
> database. So what 'instance' would C->model() return?
$c->components stores a instance of each loaded component (see Loaded
Components table on startup).
Even DBIC/CDBI models have such a instance, it's really not complicated.
--
sebastian
More information about the Catalyst
mailing list