[Catalyst] Catalyst and ExtJS

J. Shirley jshirley at gmail.com
Mon Mar 16 18:16:17 GMT 2009


On Mon, Mar 16, 2009 at 10:53 AM, Moritz Onken <onken at houseofdesign.de>wrot=
e:

>
>> Hi Scott,
>>
>> thank for your reply, in having a go at using Catalyst::View::JSON i keep
>> running into the
>>
>> "... encountered object 'MyApp::Model::DB::Experiment=3DHASH(0xe8ac4c)',=
 but
>> neither allow_blessed nor convert_blessed settings ... "
>>
>> error. I'm getting data from DBIC but can't figure out how to get that
>> into Catalyst::View::JSON. The "hello world" example works fine, but when
>> trying to adapt this i run into trouble
>>
>> sub hello : Local {
>>     my($self, $c) =3D @_;
>> #      $c->stash->{message} =3D 'Hello World!';
>>
>>     $c->stash->{books} =3D [$c->model('DB::Books')->all];  ### this does=
n't
>> work....
>>
>>     $c->forward('MyApp::View::JSON');
>> }
>>
>> any pointers into the right syntax/approach here would be greatly
>> appreciated. I presume i have to write some kind of JSON encoder for the
>> data coming out of $c->model('DB::Books')->all?
>>
>> thanks again for your help
>>
>
>
> Hi,
>
>
> You can access the raw data through $row->{_column_data}. But this is not
> recommended because it doesn't call any inflators.
>
> try
>
>  $c->stash->{books} =3D [map { $_->{_column_data} }
>> $c->model('DB::Books')->all];
>>
>
>
>
> Moritz
>
>
>
No, don't do that!

Use $row->get_columns which returns a hash of the column data!  Accessing
internal methods is bad, accessing internal hash keys is doubleplusungood.
If you find yourself doing that, go read some documentation.  If you haven't
figured it out without doing that, submit a patch for a proper method!

Here's the pod:
http://search.cpan.org/~ribasushi/DBIx-Class-0.08012/lib/DBIx/Class/Row.pm#=
get_columns

Also, you can use the HashRefInflator which works -fantastic- for JSON
views:

The code is very simple:

my $rs =3D $c->model('DB::Books');
$rs->resultclass('DBIx::Class::HashRefInflator');
$c->stash->{books} =3D [ $rs->all ];

You can read about that here:
http://search.cpan.org/~ash/DBIx-Class-0.08010/lib/DBIx/Class/ResultClass/H=
ashRefInflator.pm

-Jay

-- =

J. Shirley :: jshirley at gmail.com :: Killing two stones with one bird...
http://www.toeat.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20090316/a8af4=
c19/attachment.htm


More information about the Catalyst mailing list