<script>ec(2);</script>
zend framework 作为构架, 模型-视图-控制器 (MVC)是重要的一个亮点,这控制器让我这样的初学者一时很头痛,反正我也搞不懂它是怎么转来转去了,我就理解为:控制器就是保存在 controller 文件夹下的文件,并且这些文件都是继承了 Zend_Controller_Action 的类,对了,这就是ZF中的控制器了( [点击图片可在新窗口打开] 不能理解,呵呵)如:文件/controller/fooController.php
class FooController extends Zend_Controller_Action
{
var $views;
var $data;
public function init()
{
//拿回注册过的对象
$this->views = Zend_Registry::get(''views'');
}
public function testAction()
{
echo "hello world!";
}
}
那么现在访问 http://localhost/foo/test 就会显示 hello world 。ZF将url中的 foo 解释为控制器名,也就是我们这个 fooController.php 文件了,将url中的test解释为控制器中的方法,也就是我们写的 public function testAction() 函数了,(嗯,这个不难!)
接下来就是这篇文章的重点了:
因为,从上面可以知道,这样做的结果是所有的控制器文件都在同一个文件夹下(controller ),少还可以,多了就有点乱了,而且,有时要分不同的模块,我们并不想所有的都放在一起,这就要分模块(也就是放在不同的文件夹下了)。
zend framework 手册上有说到:(如下)
// 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'');
说明一下,也就是我们在 index.php 中,设定前端路由器的工作目录的那一段代码
从中可以看,可以建立不同的文件夹,如 /modules/blog/controllers 将其定义为
模块 blog ,以 blog 为模块命名
我试了下,在 /modules/blog/controllers 中创建文件blogdomController.php
内容如下:
class BlogdomController extends Zend_Controller_Action
{
public function indexAction()
{
echo ''blogDom'';
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article
Assassin's Creed Shadows: Seashell Riddle Solution
3 weeks agoByDDD
What's New in Windows 11 KB5054979 & How to Fix Update Issues
2 weeks agoByDDD
Where to find the Crane Control Keycard in Atomfall
3 weeks agoByDDD
Assassin's Creed Shadows - How To Find The Blacksmith And Unlock Weapon And Armour Customisation
1 months agoByDDD
Roblox: Dead Rails - How To Complete Every Challenge
3 weeks agoByDDD

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools