On Nov 15, 2007, at 11:31 PM, Les Fletcher wrote:

That one seems to use as explicit "view" at the end of the url instead of having the identifier be the last piece of the url.

To have one without the 'view', just use an empty PathPart like 'default' below...

The one problem with your design though, is the trouble with being able to support either an id or an argument (like 'create') as the second item in the field. Because of the problems with that, I usually use an explicit 'id' part to identify where the id starts, like so...

sub base : Chained('/') PathPart('namespace') CaptureArgs(0) { }

sub id : Chained('base') PathPart('id') CaptureArgs(1) {
        my ( $self, $c, $id ) = @_;
        $c->stash->{ 'object' } $c->model( 'MyModel' )->find( $id );
}

sub edit : Chained('id') PathPart('edit') Args(0) { }

sub view : Chained('id') PathPart('view') Args(0) { }

sub default : Chained('id') PathPart('') Args(0) {
        my ( $self, $c ) = @_;
        $c->forward( 'view' );
}

sub create : Chained('base') PathPart('create') Args(0) { }

This way things that you can do without a specific object (like 'create', 'list', 'search') just get chained to 'base', while things that require an object ('edit', 'view', 'delete') get chained to 'id', which is responsible for finding and stashing the object (I also usually put the access control stuff there to determine if the user is allowed to view/edit/delete that object.)


Peter Karman wrote:
Les Fletcher wrote on 11/15/07 1:47 PM:

I have question about setting up PathPart's and Chaining. I am trying
to set something that has the following look:

/namespace/ => This lists out a list of objects
/namespace/<id> => displays detail information about the object with the
numeric id=<id>
/namespace/<id>/edit => brings up a form to edit object with numeric
id=<id>
/namespace/create => brings up a form to create a new object



This controller implements that exact API:

http://search.cpan.org/~karman/Catalyst-Controller-Rose-0.04/lib/Catalyst/Controller/Rose/CRUD.pm



_______________________________________________
List: [email protected]
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/
Dev site: http://dev.catalyst.perl.org/


--
Jason Kohles, RHCA RHCDS RHCE
[EMAIL PROTECTED] - http://www.jasonkohles.com/
"A witty saying proves nothing."  -- Voltaire



_______________________________________________
List: [email protected]
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/
Dev site: http://dev.catalyst.perl.org/

Reply via email to