Chinaunix首页 | 论坛 | 博客
  • 博客访问: 308983
  • 博文数量: 106
  • 博客积分: 1948
  • 博客等级: 上尉
  • 技术积分: 947
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-27 00:11
文章分类

全部博文(106)

文章存档

2014年(1)

2013年(14)

2012年(61)

2011年(30)

分类: 系统运维

2012-01-24 23:32:17

1先建立一个控制器 名为test

  1. script/myapp_create.pl controller test
  2. exists "/var/www/myApp/script/../lib/myApp/Controller"
  3. exists "/var/www/myApp/script/../t"
  4. created "/var/www/myApp/script/../lib/myApp/Controller/test.pm"
  5. created "/var/www/myApp/script/../t/controller_test.t"
2检测一下是否成功了 多了红色字体的就是成功了
  1. script/myapp_test.pl
  2. [debug] Debug messages enabled
  3. [debug] Statistics enabled
  4. [debug] Loaded plugins:
  5. .----------------------------------------------------------------------------.
  6. | Catalyst::Plugin::ConfigLoader 0.30 |
  7. '----------------------------------------------------------------------------'
  8. [debug] Loaded dispatcher "Catalyst::Dispatcher"
  9. [debug] Loaded engine "Catalyst::Engine"
  10. [debug] Found home "/var/www/myApp"
  11. [debug] Loaded Config "/var/www/myApp/myapp.conf"
  12. [debug] Loaded components:
  13. .-----------------------------------------------------------------+----------.
  14. | Class | Type |
  15. +-----------------------------------------------------------------+----------+
  16. | myApp::Controller::Root | instance |
  17. | myApp::Controller::test | instance |
  18. '-----------------------------------------------------------------+----------'
  19. [debug] Loaded Private actions:
  20. .----------------------+--------------------------------------+--------------.
  21. | Private | Class | Method |
  22. +----------------------+--------------------------------------+--------------+
  23. | /default | myApp::Controller::Root | default |
  24. | /end | myApp::Controller::Root | end |
  25. | /index | myApp::Controller::Root | index |
  26. | /test/index | myApp::Controller::test | index |
  27. '----------------------+--------------------------------------+--------------'
  28. [debug] Loaded Path actions:
  29. .-------------------------------------+--------------------------------------.
  30. | Path | Private |
  31. +-------------------------------------+--------------------------------------+
  32. | / | /index |
  33. | /... | /default |
  34. | /test/ | /test/index |
  35. '-------------------------------------+--------------------------------------'
  36. [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

  1. sub index :Path :Args(0) {
  2.     my ( $self, $c ) = @_;

  3.     $c->response->body('Matched myApp::Controller::test in test.');
  4. }

  5. sub hello : Local {
  6.     my ( $self, $c ) = @_;
  7.     $c->response->body('hello world');
  8.     
  9. }
红色为新增加的内容
浏览器输入
/hello 就打印出 hello world了

未完待续
困了 明天再说

明天到了 补完

GET方式接受参数

  1. sub url_GET : Local {
  2.     my ( $self, $c ) = @_;
  3.     my $id = $c->req->param('id');
  4.     if ($id) {
  5.         $c->response->body("您输入了: $id");
  6.     }else{
  7.         $c->res->body("请在浏览器输入/url_GET?id=n");
  8.     }
  9. }

url输入 /url_GET?id=100
您输入了: 100




阅读(1074) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~