Zend Framework教程之MVC框架的Controller用法。具体如下:
这里简单讲讲MVC模式中Controller的基本使用方法。
基本使用实例:
root@coder-671T-M:/www/zf_demo1/application# tree.
├── Bootstrap.php
├── configs
│   └── application.ini
├── controllers
│   ├── ErrorController.php
│   └── IndexController.php
├── models
└── views
├── helpers
└── scripts
├── error
│   └── error.phtml
└── index
└── index.phtml
IndexController.php
| 1 2 3 4 5 6 7 8 9 10 11 12 | <?phpclassIndexController extendsZend_Controller_Action{  {    /* Initialize action controller here */  }  publicfunctionindexAction()  {    // action body  }} | 
规则:
1.通常Controller存放在应用的/application/controllers目录下。
可以通过以下方式自定义路径:
| 1 | Zend_Controller_Front::run('/path/to/app/controllers'); | 
或者通过以下方式自定义路径:
| 1 2 3 4 5 6 7 8 9 10 | // Set the default controller directory:$front->setControllerDirectory('../application/controllers');// Set several module directories at once:$front->setControllerDirectory(array(  'default'=> '../application/controllers',  'blog'=> '../modules/blog/controllers',  'news'=> '../modules/news/controllers',));// Add a 'foo' module directory:$front->addControllerDirectory('../modules/foo/controllers', 'foo'); | 
默认情况下存放在默认的目录即可。
2.文件名和类名相同
3.类名以Controller结尾,并且继承Zend_Controller_Action
4.类名第一个字母大写,遵守驼峰风格。利润NewsListControlle
4.文件名以Controller.php结尾
5.Controller的初始化工作可以在init方法中完成
| 1 2 3 | publicfunctioninit(){} | 
© 版权声明
本文刊载的所有内容,包括文字、图片、音频、视频、软件、程序、以及网页版式设计等部门来源于互联网,版权均归原作者所有!本网站提供的内容服务于个人学习、研究或欣赏,以及其他非商业性或非盈利性用途,但同时应遵守著作权法及其他相关法律的规定,不得侵犯本网站及相关权利人的合法权利。
联系信息:邮箱aoxolcom@163.com或见网站底部。
联系信息:邮箱aoxolcom@163.com或见网站底部。
THE END
    
















请登录后发表评论
注册
社交帐号登录