好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

ZendFramework学习日记(2)

Zend Framework 学习日记 (2)--HelloWorld 篇 这一篇主要演示如何用 zf 命令行工具建立一个基于 Zend Framework 框架的工程,也是我初学 Zend Framework 的小练习。 ( 1 )新建工程( Windows 环境下) 打开 CMD ,将目录切换到你将要新建工程所在的目录下

Zend Framework 学习日记 (2)--HelloWorld 篇

这一篇主要演示如何用 zf 命令行工具建立一个基于 Zend Framework 框架的工程,也是我初学 Zend Framework 的小练习。

( 1 )新建工程( Windows 环境下)

打开 CMD ,将目录切换到你将要新建工程所在的目录下,输入[ zf create project HelloWorld ],如下

D:/workphp/www>zf create project HelloWorld Creating project at D:/workphp/www/HelloWorld Note: This command created a web project, for more information setting up your V HOST, please see docs/README Testing Note: PHPUnit was not found in your include_path, therefore no testing a ctions will be created.

zf 会自动建立一些目录和文件,目录结构如下

关于 HelloWorld 工程的目录结构:

1. application 目录是源码放置的地方。由于 Zend 框架采用 MVC 模式,因此有 controllers 、 models 和 views 子目录,而 congfigs 子目录放置配置文件。

2. docs 目录放置文档; library 目录放 Zend Framework (由于 Zend Framework 放置在别处,并加入了 include_path ,所以该目录为空); public 目录比较重要,它就是站点发布的目录,该目录下的文件都可以通过浏览器访问; tests 目录是单元测试的目录。

3. .zfproject.xml 是 zf 工具的记录文件,有些 zf 命令会更新该文件。

注:关于 Zend Framework 的 MVC 模式,请参考 http://framework.zend.com/manual/en/learning.quickstart.intro.html

( 2 )测试 Zend Framework

确保 Apache 服务器已开启,在浏览器中输入[ http://localhost:8088/HelloWorld/public/ ],我修改了 Apache 的默认端口(怎么修改,我的另一篇文章有提到,这里 )。这时应该出现下面的界面,说明 Zend Framework 已经能正常工作了, gx !(如果没有,请参考[ Zend Framework 学习日记 (1)-- 环境搭建篇])

注:关于 url 的规则,简单点说就是, http:// 域名 (IP)/public/controller/action ,一个 controller 可以多个 action , action 就是处理 view 的, controller 控制这些 action ,默认有 IndexController 和 indexAction (见 controllers 目录下的 IndexController.php ),因此这里完整的 url 路径应该是 http://localhost:8088/HelloWorld/public/index/index 。具体参考 Zend Framework manual 。

( 3 )采用 Two Step View 设计模式

确保 CMD 在 HelloWorld 目录下面,输入[ zf enable layout ],如下

D:/workphp/www/HelloWorld>zf enable layout Layouts have been enabled, and a default layout created at D:/workphp/www/HelloW orld/application/layouts/scripts/layout.phtml A layout entry has been added to the application config file.

会发现 application 目录多了一个 layouts 目录以及该目录下的子目录 scripts 和文件 layout.phtml 。如果你仔细找找,会发现[ Welcome to the Zend Framework ]界面的代码,是在 views 目录的 scripts->index->index.phtml ,如下

安装了 Zend Studio ,可以直接打开,也可以用[记事本]或[写字板]打开。将 index.phtml 里面的内容全部删除,加入下面代码

Hello World!

查看更多关于ZendFramework学习日记(2)的详细内容...

  阅读:37次