[Catalyst] How to make chained actions nice?

Oleg Pronin syber.rus at gmail.com
Sat Apr 7 22:53:23 GMT 2007


Greetings.

I've got some kind of problem using chained actions.

There are some objects. Each object has a number of properties.

And this is how i want it to be:

URL for a list of objects is
/object/list

URL for editing object is
/object/OBJ_ID/edit (through chained action)

URL for list of object's properties
/object/OBJ_ID/property/list

URL for editing property
 /object/OBJ_ID/property/PROP_ID/edit (through 2 chained actions)

I have MyApp::Controller::Object

sub list : Local {   ....   }

sub object : Chained('/') CaptureArgs(1) {
     .... object-related-code ...
}

Problem one is that i've got to write something like this:

sub edit : Chained('object') Args(0) { ....}
                            ^^^^^^^
i can't say Chained('.') because current path is "/object" and the chain has
"/object/object" path.
I dont want to place the chain in the Root controller - this is wrong.

Problem two is how do i define last 2 urls.
In MyApp::Controller::Object::Property

sub list : PathPart('property/list') Chained('/object/object') Args(0) {
... }

this is very ugly!

and finally

sub property : Chained('/object/object') CaptureArgs(1) { ... }
sub edit : Chained('property') Args(0) { ... }  ( again, i can't say
Chained('.') )

Do i do something wrong ? Why do i have to copy-paste a half of url to
ParhPart and Chained attributes?
How do i need to organize the structure of my controllers ?

I want to define such an actions in the way like this:

Controller::Object
sub list : Local {...}                                         #
/object/list
sub object : Chained('/') CaptureArgs(1) {...}
sub edit : Chained('.') Args(0) {...}                    #/object/ID/edit

Controller::Object::Property
sub list : Chained('../') Args(0) {...}
#/object/ID/property/list
sub property : Chained('../') CaptureArgs(1) {...}
sub edit : Chained('.') Args(0) {...}
#/object/ID/property/ID/edit

Please somebody help!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20070408/e110d=
6de/attachment.htm


More information about the Catalyst mailing list