安装环境:一、基本设置:
1. 设定mod_rewrite
编辑httpd.conf如果前面的”#”字在的话,就把它拿掉吧(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.基本目录架构2. 檔案设定
a)index.php(bootstrap file),可视个别情况修改复制PHP内容到剪贴板PHP代码:
PS1:在windows系统下要做出.htaccess,可以直接用记事本来做储存的时候,选择「存储类型(T)」为「所有文件」,即可直接输入档名.htaccess而不会发生错误。
PS2:其它目录也可加个.htaccess档來保护目录里的资料,內容为:deny from all。
三、Controller设定
先设定一个最基本的IndexController,架构参考上一段落
这个是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架构做出来了。
引用:
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
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网站下载)
a)index.php(bootstrap file),可视个别情况修改复制PHP内容到剪贴板PHP代码:
复制内容到剪贴板
b).htaccess设定:代码:
<?php
//Basic Config
error_reporting(E_ALL | E_STRICT); //设定Error Report的等级
date_default_timezone_set('Asia/Taipei'); //设定时区为台北
//Include path
define ('P_S', PATH_SEPARATOR);
set_include_path('.' .P_S .'../library' .P_S .'../application/models/' .P_S .get_include_path());
require_once'Zend/Loader.php';
Zend_Loader::registerAutoload();
//Controller
$frontController = Zend_Controller_Front::getInstance();
$frontController->setControllerDirectory('../application/controllers');
$frontController->dispatch();
?>复制内容到剪贴板
基本上这样设定完,就差不多把环境搭建好了,接下來,就是开始设定各別Controller的工作了。代码:
RewriteEngine on
RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.phpPS1:在windows系统下要做出.htaccess,可以直接用记事本来做储存的时候,选择「存储类型(T)」为「所有文件」,即可直接输入档名.htaccess而不会发生错误。
PS2:其它目录也可加个.htaccess档來保护目录里的资料,內容为:deny from all。
三、Controller设定
先设定一个最基本的IndexController,架构参考上一段落
复制内容到剪贴板
1. IndexController.php复制PHP内容到剪贴板PHP代码:代码:
|-/application
|-/controllers (MVC之C)
|-IndexController.php (Index的Controller) <-新增这个文件
|-/models (MVC之M)
|-/views (MVC之V)
|-/filters
|-/helpers
|-/scripts
|-/index <--新增这个目录
|-index.phtml <--新增这个文件
|-happy.phtml <--新增这个文件复制内容到剪贴板
2. index.phtml & happy.phtml代码:
<?php
require_once 'Zend/Controller/Action.php';
class IndexController extends Zend_Controller_Action{
public function indexAction(){
//可以在写index的Action
}
public function happyAction(){
//可以在这里写happy的Action
}
}
?>这个是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架构做出来了。