[Catalyst] OT: edit/add seperate actions?
Peter Karman
peter at peknet.com
Tue Mar 3 18:33:06 GMT 2009
Iain wrote on 03/03/2009 09:33 AM:
> Hello all,
>
> So we are having a discussion @work about basic add/edit functions. We
> currently have currently two lines of thoughts on handling it.
>
> 1. Have separate actions for adding and editing e.g.
>
> # add
> /app/notice/add_new (POST To) /app/notice/process_add_new
>
> # edit
> /app/notice/*/edit (POST To) /app/notice/*/process_edit
>
> 2. Have a shared edit action with an if ( $c->req->method eq 'POST' )
> check.
>
> # edit
> /app/notice/*/edit (POST Back to) /app/notice/*/edit
>
> There currently doesn't look like much difference in lines of code to
> manage.
>
> Just wondering if anybody has any thoughts/experience, pros/cons best
> practice etc of either approach.
>
CatalystX::CRUD::Controller does:
/app/notice/create # redirect internally to 0/edit
/app/notice/*/edit # POST to /app/notice/*/save
The '0' placeholder indicates it is a new object. '0' has the nice
effect of evaluating true for defined() and length() but false
otherwise. OTOH, it means you can't have a valid OID that == 0.
If you use CatalystX::CRUD::REST, you can do:
# POST /foo -> create new record
# GET /foo -> list all records
# PUT /foo/<pk> -> update record
# DELETE /foo/<pk> -> delete record
# GET /foo/<pk> -> view record
# GET /foo/<pk>/edit_form -> edit record form
# GET /foo/create_form -> create record form
CatalystX::CRUD::REST uses the C::R::REST::ForBrowsers feature of
'x-tunneled-method' param to support PUT and DELETE via POST.
--
Peter Karman . peter at peknet.com . http://peknet.com/
More information about the Catalyst
mailing list