1 set_include_path 函数很重要。
我们发现ZF框架中每个文件都有 require_once 'Zend/name.php'; 这样的导入语句,这意味着Zend框架包在网站的位置是站点根目录下Zend文件夹内。
但是开发者一般喜欢把框架这种非自己开发的文件统一放在lib文件夹内,或者放在站点文件夹以外的地方以防止被用户访问。
set_include_path()函数可以添加php中导入的目标路径,就像CMD中的
SET PATH = C:/JDK;%PATH% 一样。
假设Zend放在lib文件夹内,而lib文件夹在站点根目录,我们可以这样:
set_include_path('.' .PATH_SEPARATOR .'./lib'.PATH_SEPARATOR .get_include_path());
这样就可以顺利导入了。
2 ZF的入口文件其实很简单
ZF的入口文件的文件名必须是index.php(FLEA框架中,入口文件可以随便,比如设置成app.php),文件的内容可以很简单:
<?php
set_include_path('.' .PATH_SEPARATOR .'./lib'.
PATH_SEPARATOR .'./app/models/'.
PATH_SEPARATOR .get_include_path());
require_once 'Zend/Controller/Front.php';
Zend_Controller_Front::run("app/controllers");
?>
设置导入库的目录,导入MVC中的启动包,设置MVC中的C的目录,然后启动
3 大小写很重要
MVC中的C文件的格式必须为:XxxController.php 其中的Xxx表示控制器名称,第一个字母必须大写,其他字母必须小写,即便你想命名一个SOAPController.php,你也得改成 SoapController.php 。还有函数的命名规则,必须是 public function xxxAction(){}
4 APACHE的配置很重要
LoadModule rewrite_module modules/mod_rewrite.so 开启rewrite功能。
然后将
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Allow From None
</Directory>
改成
<Directory />
Options FollowSymLinks
AllowOverride all
Order deny,allow
Allow From all
</Directory>
5 .htaccess文件不可少
当我看到这个文件的额文件名时很不屑,以为这个可以忽略不计,结果导致URL不能正常解析。这个文件必须与index.php在同目录,内容为:
RewriteEngine on
RewriteRule !/.(js|ico|gif|jpg|png|css|html)$ index.php
以下是我最终的目录结构和文件内容:
app
controllers
IndexController.php
lib
Zend
index.php
.htaccess
其中的 IndexController.php:
<?php
class IndexController extends Zend_Controller_Action
{
public function init()
{
$this->_helper->viewRenderer->setNoRender();
}
public function indexAction()
{
echo "indexAction";
}
public function myactAction()
{
echo "myactAction";
}
}
?>
$this->_helper->viewRenderer->setNoRender();这一句是屏蔽Zend自带的MVC中的V。我想用其他JS框架来提供V,前后台用AJAX通信。
配置zend framework
最新推荐文章于 2024-06-21 10:00:31 发布