|
|

Zend Framework安装
安装环境:
Windows XP Professional(SP2)
Appserv(Apache 2.2.4, PHP/5.2.3, MySQL 5.0.45)
Zend Framework 1.0.1(2007-07-30)
一、基本设置:
1. 设定mod_rewrite
编辑httpd.conf
#LoadModule rewrite_module modules/mod_rewrite.so
如果前面的”#”字在的话,就把它拿掉吧(mod_rewrite的详细资料,可参考apache网站)
2. 设定include_path
设定include path之目的,是为了方便在include类别时,省去输入长长一串位置的时间。
a) 可直接修改php.ini之设定
b) 或是于程序中动态加入set_include_path
参考网址:http://tw2.php.net/set_include_path
3. 设定httpd.conf之document root
请参考下一段之目录架构,将document root指向/html,设定完之后,请重新启动Apache,并建议检查一下error.log看是否有错误的地方。
二、Zend Framework设定
1.基本目录架构
|-/application
|-/controllers (MVC之C)
|-/models (MVC之M)
|-/views (MVC之V)
|-/filters
|-/helpers
|-/scripts
|-/html
|-/images (存放图片)
|-/scripts (存放script)
|-/styles (存放CSS)
|-.htaccess (配合url rewrite之资料)
|-index.php (bootstrap file)
|-/library
|-/Zend (这个是ZF的library,可从ZF网站下载)
2. 档案设定
a)index.php(bootstrap file),可视个别情况修改
b).htaccess设定:
RewriteEngine on
RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php
基本上这样设定完,就差不多把环境搭建好了,接下来,就是开始设定各别Controller的工作了。
PS1:在windows系统下要做出.htaccess,可以直接用记事本来做储存的时候,选择「存储类型(T)」为「所有文件」,即可直接输入档名.htaccess而不会发生错误。
PS2:其它目录也可加个.htaccess档来保护目录里的资料,内容为:deny from all。
三、Controller设定
先设定一个最基本的IndexController,架构参考上一段落
|-/application
|-/controllers (MVC之C)
|-IndexController.php (Index的Controller) <-新增这个文件
|-/models (MVC之M)
|-/views (MVC之V)
|-/filters
|-/helpers
|-/scripts
|-/index <--新增这个目录
|-index.phtml <--新增这个文件
|-happy.phtml <--新增这个文件
1. IndexController.php
2. index.phtml & happy.phtml
这个是indexAction的view,当执行indexAction时,预设会寻找相同的文件名,并render出页面内容
Controller的设定大概这样就完成了(细节可再参考ZF的Document或是其它高手们的Tutorial)
接下来,打开browser,输入网址:
http://127.0.0.1/ 或是 http://127.0.0.1/index 这两个网址,它都会找IndexController里index这个action
然后会找index.phtml来render页面内容 http://127.0.0.1/index/happy
它则是会找IndexController里happy这个action,然后会找happy.phtml来render页面内容。基本上到这里,就把这个小小的MVC架构做出来了。 |
|