Zend Framework 配置另一则(较详细)
论坛链接
- Zend Framework 配置另一则(较详细)
- 发布时间:2009-07-29 14:09:39 浏览数:9685 发布者:superadmin 设置字体【大 中 小】
本文是以购买虚拟主机的空间为例,讲述Zend Framework的配置。
网上大多教程需要修改httdconf或php.ini, 对于购买虚拟主机空间的朋友来说是不实用的。
毕竟,现在不是人人都能拥有自己的主机
注意:要使用zend framework,你的空间至少要:
1) php5.14以上的版本
2)必须支持Url rewrite功能
(目前80%的PHP空间都支持URL rewrite)
1.下载zend framework,解压后把library里面的zend放到网站的根目录。
2.测试url rewrite功能,新建一份名为.htaccess的文件,注意:是只有扩展名,没有文件名的。
可参考http://www.37dg.com/tutorial/282.jsp windows下如何创建.htaccess
.htaccess文件内容如下:
RewriteEngine on
RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php
在网站根目录下创建 index.php
<?
echo "Hello world";
?>
http://www.域名.com/index.php 如果能正常访问
在创建了.htaccess文件后,无论你把index.php 改成什么名称,如abc.php adsdsd.php 234324.php等。
实际上都是访问index.php
这正是zend framework需要的url rewrite功能,所有的请求都会转给index.php处理。限制了网站只有一个入口
3.开始配置zend framework
在网站根目录下按以下结构新建文件夹
application/
controllers/
models/
views/
scripts/
index/
helpers/
filters/
.htaccess
index.php
zend/
其中zend/就是第一步中下载放到根目录的zend
注意:必须按照上面的步骤创建好文件夹
在上面的controllers下建立一文件,文件名为:IndexController.php
内容如下:
<?
require_once 'Zend/Controller/Action.php';
class IndexController extends Zend_Controller_Action
{
public function IndexAction()
{
}
public function aaAction()
{
echo "this is aa action output<br>";
}
}
?>
再在上面的application\views\scripts\index下面建立一 index.phtml
内容如下:
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>My first Zend Framework App</title></head>
<body>
<h1>Hello, World!</h1>
This is views HTML
</body>
</html>
再在application\views\scripts\index建立一aa.phtml
内容如下:
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>My first Zend Framework App</title></head>
<body>
This is AA action views<br>
</body>
</html>
假设域名是www.domain.com
http://www.domain.com/ 这时就能看到zend framework运行的效果
http://www.domain.com/index 和上面的效果一样
http://www.domain.com/index/aa 这个就是运行了上面的aaActiion
这就是zend framwork最简单的实例配置了, 上面只用到了MVC的C和V,将读写数据库的方法写在
models文件夹下,这就是MVC架构的网站了.希望对未入门zend framework的你有帮助.
Http://zendf.com -- Zend Framework 中文站