[Catalyst] How to make chained actions nice?
Danny Warren
danny at io.com
Sat Apr 7 23:18:15 GMT 2007
The Chained('.') parameter is used for chaining across controllers. I
understand your URI layout from your comments, but I don't understand
what you are trying to do with all those weird Chained params you are using.
Here is how I would lay it out. Read the perldoc again, it took me a
few read-throughs to completely grok the subtleties of how chains work.
In MyApp::Controller::Object...
# Responds to /object/list
sub list : Local { ... }
# Captures object id, as in /object/[OBJ_ID]
sub object : PathPart('object') Chained CaptureArgs(1) { ... }
# Responds to /object/[OBJ_ID]/edit
sub edit : Chained('object') Args(0) { ... }
# Chain point for chaining to property controller
# NOTE: This is just a jump point, don't put bizlogic in here,
# put it in the property controller
sub property : Chained('object') CaptureArgs(0) { ... }
In MyApp::Controller::Object::Property
# Responds to /object/[OBJ_ID]/property/list
sub list : Chained('.') Args(0) { ... }
# Captures property id, as in /object/[OBJ_ID]/property/[PROP_ID]
sub property : PathPart('') Chained('.') CaptureArgs(1) { ... }
# Responds to /object/[OBJ_ID]/property/[PROP_ID]/edit
sub edit : Chained('property') Args(0) { ... }
Hope that helps!
Danny Warren
Oleg Pronin wrote:
> 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!
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> List: Catalyst at lists.rawmode.org
> Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
> Dev site: http://dev.catalyst.perl.org/
More information about the Catalyst
mailing list