Zend Framework 1.5.x 入门教程(简体中文版)
RewriteRule 非常简单,可理解为“对所有不能映射到磁盘上已存在的文件的 url,都用 index.php 来代替”。
为了安全起见,我们设定了一些 PHP 的 ini 设置;我们还将 short_open_tag 选项设置为 on,因为将来视图
文件可能会用到它。当然这些设置可能已经正确设置过了,但我们必须确保这一点。注意只有在使用 PHP
模块(mod_php)的方式下才可以在.htaccess 文件中使用 php_flag 标记。如果使用 CGI/FastCGI 模式,必须保
证在 php.ini 中正确设置了这些参数。注意,为了让.htaccess 起作用,必须在 httpd.conf 中将配置指令
AllowOverride 设置为 All.
引导文件: index.php
zf-tutorial/public/index.php 是应用程序的引导文件,我们用下面的代码开始我们的教程:
zf-tutorial/public/index.php
<?php
error_reporting(E_ALL|E_STRICT);
ini_set('display_errors', 1);
date_default_timezone_set('Europe/London');
// 目录设置和类装载
set_include_path('.' . PATH_SEPARATOR . '../library/'
. PATH_SEPARATOR . '../application/models'
. PATH_SEPARATOR . get_include_path());
include "Zend/Loader.php";
Zend_Loader::registerAutoload();
// 设置控制器
$frontController = Zend_Controller_Front::getInstance();
$frontController->throwExceptions(true);
$frontController->setControllerDirectory('../application/controllers');
// run!
$frontController->dispatch();
注意在文件的结尾我们没有加上 ?>,因为在文件的结尾它不是必需的。这样可以避免产生一些难于调试的
错误问题。例如,在使用 header()函数来重定向(redirect)时,如果在其前面某个包含文件中 ?> 后面不小心
加上了空格就会出现错误。
下面开始详细解释这个文件:
error_reporting(E_ALL|E_STRICT);
ini_set('display_errors', 1);
date_default_timezone_set('Europe/London');
前 2 行保证在程序出错时能看到相应的错误信息。第 3 行设置了时区(PHP 5.1+以后要求如此)。当然,你
应该选择自己所在地的时区。
翻译:Altair (简体中文版 v0.12) http://www.phpatoz.com/ (Under Construction) 第 5 页 共 25 页
评论0
最新资源