Zend Framework教程之MVC框架的Controller用法分析
2019/6/30 16:42:33
本文主要是介绍Zend Framework教程之MVC框架的Controller用法分析,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
本文讲述了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
<?php class IndexController extends Zend_Controller_Action { public function init() { /* Initialize action controller here */ } public function indexAction() { // action body } }
规则:
1.通常Controller存放在应用的/application/controllers目录下。
可以通过以下方式自定义路径:
Zend_Controller_Front::run('/path/to/app/controllers');
或者通过以下方式自定义路径:
// 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方法中完成
public function init() { }
更多关于zend相关内容感兴趣的读者可查看本站专题:《Zend FrameWork框架入门教程》、《php优秀开发框架总结》、《Yii框架入门及常用技巧总结》、《ThinkPHP入门教程》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》
希望本文所述对大家PHP程序设计有所帮助。
这篇关于Zend Framework教程之MVC框架的Controller用法分析的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-03-29env: php: no such file or directory
- 2024-03-01php foreach break
- 2024-02-26Exception参数 php-icode9专业技术文章分享
- 2023-12-30PHP文件批量上传-icode9专业技术文章分享
- 2023-12-30thinkphp6 withJoin-icode9专业技术文章分享
- 2023-12-27MagicArray:像php一样,让Go业务代码不再卷!
- 2023-11-18centos7编译安装PHP教程。
- 2023-11-18centos7编译安装phpMyAdmin教程。
- 2023-10-13唱衰这么多年,PHP 仍然还是你大爷!
- 2023-07-25PHP8,性能更好,语法更好,类型安全更完善