[Catalyst] Using C::C::FormBuilder With DBIC

hkclark at gmail.com hkclark at gmail.com
Sun Feb 18 12:27:53 GMT 2007


On 2/18/07, RA Jones <ra.jones at dpw.clara.co.uk> wrote:
>
> > Any suggestions?  What are other folks doing for C::C::FormBuilder and
> DBIC?
>
> I'm pretty new to this, but this is what I did:
>
> sub edit : Local Form {
>
>    # get data into form pretty much as above, then:
>
> if ( $form->submitted && $form->validate ) {
>    $c->stash->{user} =3D $user;
>    $c->forward('do_edit');
> }
>
> sub do_edit : Private {
>    my ($self, $c) =3D @_;
>    my $form =3D $self->formbuilder;
>    my $fields =3D $form->field;
>    $c->stash->{user}->update($fields);
>    $c->flash->{status_msg} =3D 'User updated';
>    $c->response->redirect( $c->req->base . 'users/view/' .
>      $c->stash->{user}->id );
> }
>
> Not sure if it's the 'best' way, but it works. Will be interesting to
> see what other suggestions you get.
> --
> Richard Jones
> Leeds, UK
> mailto:ra.jones at dpw.clara.co.uk


Hi Richard,

Thank you very much for your suggestion.  Argh!  That crossed my mind when I
saw ResultSet->update() in the docs, but I incorrectly looked at
Row->update() (which doesn't support a hashref of fields to update) and
convinced myself it wouldn't be possible (but Row obviously doesn't
represent a single object returned by ResultSet, so I should have stuck with
the docs for ResultSet->update!).  That's what I get for staying up too late
playing with this vs. getting some sleep and trying it the next AM. :-(

I would still be interested to see if other folks have alternative
solutions.  It's also interesting to see how folks break up the flow of the
initial form display vs. the form updating (in one method of the controller
vs. multiple methods, how they organize it, etc.).  Are there any
recommendations on "best practices"?

Thanks,
Kennedy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20070218/9e048=
9f9/attachment.htm


More information about the Catalyst mailing list