最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
zend历程 之 多模块控制器
时间:2008-04-24 编辑:简简单单 来源:一聚教程网
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'';
控制器就是保存在 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'';
-
下一个: zend历程 之 初认控制器
相关文章
- PHP导出数据超时的优化建议解读 10-31
- PHP之mysql位运算解析 10-31
- Laravel实现登录跳转功能解析 10-31
- php双向队列解读 10-31
- Laravel异常上下文解决教程 10-24
- php数组查询元素位置方法介绍 10-24