1先建立一个控制器 名为test
- script/myapp_create.pl controller test
-
exists "/var/www/myApp/script/../lib/myApp/Controller"
-
exists "/var/www/myApp/script/../t"
-
created "/var/www/myApp/script/../lib/myApp/Controller/test.pm"
-
created "/var/www/myApp/script/../t/controller_test.t"
2检测一下是否成功了 多了红色字体的就是成功了
- script/myapp_test.pl
-
[debug] Debug messages enabled
-
[debug] Statistics enabled
-
[debug] Loaded plugins:
-
.----------------------------------------------------------------------------.
-
| Catalyst::Plugin::ConfigLoader 0.30 |
-
'----------------------------------------------------------------------------'
-
-
[debug] Loaded dispatcher "Catalyst::Dispatcher"
-
[debug] Loaded engine "Catalyst::Engine"
-
[debug] Found home "/var/www/myApp"
-
[debug] Loaded Config "/var/www/myApp/myapp.conf"
-
[debug] Loaded components:
-
.-----------------------------------------------------------------+----------.
-
| Class | Type |
-
+-----------------------------------------------------------------+----------+
-
| myApp::Controller::Root | instance |
-
| myApp::Controller::test | instance |
-
'-----------------------------------------------------------------+----------'
-
-
[debug] Loaded Private actions:
-
.----------------------+--------------------------------------+--------------.
-
| Private | Class | Method |
-
+----------------------+--------------------------------------+--------------+
-
| /default | myApp::Controller::Root | default |
-
| /end | myApp::Controller::Root | end |
-
| /index | myApp::Controller::Root | index |
-
| /test/index | myApp::Controller::test | index |
-
'----------------------+--------------------------------------+--------------'
-
-
[debug] Loaded Path actions:
-
.-------------------------------------+--------------------------------------.
-
| Path | Private |
-
+-------------------------------------+--------------------------------------+
-
| / | /index |
-
| /... | /default |
-
| /test/ | /test/index |
-
'-------------------------------------+--------------------------------------'
-
-
[info] myApp powered by Catalyst 5.90007
还可以用prove --lib t/controller_test.t 来检测
默认情况下在浏览器输入
会显示下面的文字
Matched myApp::Controller::test in test.
编辑一下刚才建立的控制器
vi lib/myApp/Controller/test.pm
- sub index :Path :Args(0) {
-
my ( $self, $c ) = @_;
-
-
$c->response->body('Matched myApp::Controller::test in test.');
-
}
-
-
sub hello : Local {
-
my ( $self, $c ) = @_;
-
$c->response->body('hello world');
-
-
}
红色为新增加的内容
浏览器输入
/hello 就打印出 hello world了
未完待续
困了 明天再说
明天到了 补完
GET方式接受参数
- sub url_GET : Local {
-
my ( $self, $c ) = @_;
-
my $id = $c->req->param('id');
-
if ($id) {
-
$c->response->body("您输入了: $id");
-
}else{
-
$c->res->body("请在浏览器输入/url_GET?id=n");
-
}
-
}
url输入 /url_GET?id=100
您输入了: 100
阅读(1074) | 评论(0) | 转发(0) |