Home > catalyst > | perl > $c->uri_for_actionの引数

$c->uri_for_actionの引数

やっと理解できたのでメモ。uri_for_actionはドキュメントによると次のような構文になる。
$c->uri_for_action( $path, \@captures?, @args?, \%query_values? )
この“\@captures”と“@args”がそれぞれアトリビュートの“CaptureArgs”、“Args”に対応する。

例として、次のようなチェーンドアクションを考える。ユーザー情報を編集するようなページを想定している。
Path SpecPrivate
/user/*/*/info/*/edit/* /user/root (2)
-> /user/info (1)
=> /user/edit
ソースはこんな感じ。
package MyApp::Controller::User;
use Moose;
use namespace::autoclean;
BEGIN { extends "Catalyst::Controller"; }
sub root : Chained( "/" ) PathPrefix CaptureArgs( 2 ) {
    my ( $self, $c, $arg1, $arg2 ) = @_;
    # まずここに来る
}
sub info : Chained( "root" ) CaptureArgs( 1 ) {
    my ( $self, $c, $arg3 ) = @_;
    # 次にここに来る
}
sub edit : Chained( "info" ) Args( 1 )
    my ( $self, $c, $id ) = @_;
    # ここで終了
}
__PACKAGE->meta->make_immutable;
このとき、次のようなURLを作成したい場合は、
http://localhost:3000/user/ARG1/ARG2/info/ARG3/edit/USER-ID
次のように書けばよい。
[%# Template::Toolkitでの例 %]
[% c.uri_for_action( "/user/edit", [ "ARG1", "ARG2", "ARG3" ], "USER-ID" ) %]

Comments:0

Comment Form

Trackbacks:0

TrackBack URL for this entry
http://blog.remora.cx/mt/mt-tb.fcgi/5
Listed below are links to weblogs that reference
$c->uri_for_actionの引数 from blog.remora.cx

Home > catalyst > | perl > $c->uri_for_actionの引数

Feeds
CC Licence

Creative Commons License

このブログはクリエイティブ・コモンズでライセンスされています。

W3C Validation

I ♥ validator

Return to page top