本文讲述了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
						  | 
<?php
class IndexController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
}
public function indexAction()
{
// 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
						  | 
public function init()
{
}
 | 
希望本文所述对大家PHP程序设计有所帮助。
相关文章
- 64M VPS建站:怎样选择合适的域名和SSL证书? 2025-06-10
 - 64M VPS建站:怎样优化以提高网站加载速度? 2025-06-10
 - 64M VPS建站:是否适合初学者操作和管理? 2025-06-10
 - ASP.NET自助建站系统中的用户注册和登录功能定制方法 2025-06-10
 - ASP.NET自助建站系统的域名绑定与解析教程 2025-06-10
 
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
 - 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
 - 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
 - 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
 - 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
 
快网idc优惠网
QQ交流群
- 
            2025-05-29 28
 - 
            2025-05-29 93
 - 
            2025-06-04 85
 - 
            
在 VPS 服务器上部署 DeepSeek 需要什么配置?怎么部署?
2025-05-25 100 - 
            2025-05-27 33
 
        
    		
            	
        
        