发布于 2016-04-02 20:53:44 | 146 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的Zend Framework中文手册,程序狗速度看过来!

Zend Framework PHP开源框架

Zend Framework(简写ZF)是由 Zend 公司支持开发的完全基于 PHP5 的开源PHP开发框架,可用于开发 Web 程序和服务,ZF采用 MVC(Model–View-Controller) 架构模式来分离应用程序中不同的部分方便程序的开发和维护。


这篇文章主要介绍了Zend Framework教程之MVC框架的Controller用法,简单分析了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()
{
}



最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务