[Catalyst] Very Simple Question
Jonathan Hall
jonh at nmgi.com
Mon Nov 17 17:07:06 GMT 2008
In most cases, you can do simply: $element->title
You can *not* do this in cases where 'title' is also the name of a
relationship in the $element DBIC object; in such cases you can
accomplish the same with: $element->get_column('title')
You can also create a method in your DBIC ResultSet called 'title' that
does fancy things if you want:
sub title {
my ( $self ) = @_;
return $self->get_column('title') || "Untitled Document";
}
Then you can use the first format ($element->title), to get at your
self-defined method.
I hope this all helps :)
Amiri Barksdale wrote:
> I am a new user of Catalyst, and from reading the documents and
> reading blogs posts I have been able to set up my schema, my authz/
> authen, sessions, and my Mason view. I have a very simple question,
> though.
>
> This in a controller
>
> $c->stash->{elements} = [$c->model('DB::Elements')->all];
>
> Requires this in a view:
>
> <% $element->{_column_data}->{title} %>
>
> Is there a more transparent way to use DBIC so that I don't have this
> intermediate hash ref in the middle of my object? I'd like to be able
> to do
>
> <% $element->{title} %>
>
> It seems like TT does this automatically?
>
> Amiri
>
> _______________________________________________
> List: Catalyst at lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/
>
--
Inbound and outbound email scanned for spam and viruses by the
DoubleCheck Email Manager: http://www.doublecheckemail.com
More information about the Catalyst
mailing list