[Catalyst] best way to create a flexible, multiple key, CRUD application?

Francesc Romà i Frigolé francesc.roma+catalyst at gmail.com
Mon Feb 19 00:26:10 GMT 2007


Mark,

Your words are very encouraging: I'll happily trade 50% more work for
getting rid of the black magic ( and get some peace of mind )

I'll start over with your examples.Thank you very much,
Francesc



On 2/18/07, Mark Zealey <mark at itsolve.co.uk> wrote:
>
> I looked at the crud modules but i could never really get them to work;
> they
> were always rather too limited for me and if you ever want to extend it
> slightly; you will have to rewrite it all yourself. It's easy enough to do
> a
> simple crud app yourself; you want to use DBIx::Class probably with the
> Schema::Loader module at least during development. use the FormBuilder
> controller base class, with .fb file like:
>
> name: invite
> method: post
> fields:
>     name:
>         label: Name
>         required: 1
>     number:
>         label: Number of people
>         validate: INT
>         value: 1
>         required: 1
>     address:
>         label: Postal address
>         type: textarea
>         rows: 6
>         cols: 40
>         required: 0
>     email:
>         label: Email Address
>         required: 0
>     coming:
>         label: Coming?
>         options: 1=3DYes, 0=3DNo
>         required: 0
>
>
> and then just write a little glue code; something like:
>
> package Zealey::Controller::Invite;
> use strict;
> use warnings;
>
> use base 'Catalyst::Controller::FormBuilder';
>
> sub index : Private {
>     my ($self, $c) =3D @_;
>     $c->res->redirect($c->uri_for('view'));
> }
>
> sub add : Local Form('/invite/main') {
>     my ($self, $c) =3D @_;
>
>     my $form =3D $self->formbuilder;
>
>     $form->submit('Add new invite');
>
>     if($form->submitted and $form->validate) {
>         $c->model('Zealey::Invite')->create($form->fields)
>         $c->res->redirect($c->uri_for('view'));
>     }
> }
>
> sub update : Local Form('/invite/main') {
>     my ($self, $c, $id) =3D @_;
>
>     my $form =3D $self->formbuilder;
>
>     $form->submit('Update invite');
>
>     my $db =3D $c->model('Zealey::Invite')->find($id) or die "$id not
> found";
>
>     if($form->submitted) {
>         if ($form->validate) {
>             $db->set_columns($form->fields);
>             $db->update;
>             $c->res->redirect($c->uri_for('view'));
>         }
>     } else {
>        # Fill in form
>         $form->field( name =3D> $_, value =3D> $db->$_ ) for @DB_COLS
>     }
> }
>
> sub delete : Local {
>     my ($self, $c, $id) =3D @_;
>
>     my $db =3D $c->model('Zealey::Invite')->find($id) or die "Not found";
>     $db->delete;
>     $c->res->redirect($c->uri_for('view'));
> }
>
> sub view : Local {
>     my ($self, $c) =3D @_;
>
>     $c->stash->{rows} =3D [ $c->model('Zealey::Invite')->all ];
> }
>
> 1;
>
> I use a View::TT module; you just stick [% FormBuilder.render %] in the
> add/update files; and some sort of table renderer for each column in the
> view
> one iterating over the 'rows' variable.
>
> Admittedly; this is probably 50% more complicated than setting up
> InstantCRUD
> or the HTML::Widget::DBIC module, but it is very easily extendable as it
> is
> not really tied to any particular framework - it would be trivial for
> example
> to change it to link across 2 tables by simply issuing the create/update
> statements and using foreign key constraints. It's much less
> black-magic'y;
> it's easy to see everything that's happening but at the same time not see
> the
> bits you don't really care about.
>
> Mark
>
>
>
> On Sunday 18 February 2007 5:41 pm, Francesc Rom=E0 i Frigol=E9 wrote:
> > Hello,
> >
> > I want to create a web application which is basically CRUD, and I was
> > wondering if there is a scaffolding script that can do it for catalyst.
> It
> > has to support tables with composite primary keys.
> >
> > I thought InstantCRUD would be a good solution but i quickly discovered
> > that it doesn't handle composite primary keys ( it actually says it on
> the
> > documentation ). I naively thought that it wouldn't take much time to
> add
> > such functionality, and I started preparing a patch for it. I actually
> > managed it to work for Edit/Update and Delete (I think so), but I got
> stuck
> > with the Create part. The problem is, at least, that InstantCRUD depends
> on
> > DBSchema.pm which has the same limitation.
> >
> > Now I got the feeling I'm wasting my time because somebody must already
> > have a solution for this problem, right?
> >
> > BTW: I've seen a lot of talk about Reaction on the list recently but I
> > haven't quite got what is it about, and apparently is undocumented. Does
> it
> > have any relation with CRUD?
> >
> > thanks in advance,
> > Francesc
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20070219/c99f1=
fa3/attachment.htm


More information about the Catalyst mailing list