WAMP下 搭建Zend Framework(Hello World)实例

一、环境搭建

1、下载安装Zend Framework,此步骤不再详细叙述

2、配置php.ini文件

打开php.ini文件,可以找到如下的代码:

; Windows: "\path1;\path2"
;include_path = ".;c:\php\includes"

修改为include_path = ".;d:\zend_framework\ZendFramework-1.12.3\library" (Zend Framework安装包中的文件目录library)

3、修改httpd.conf文件

1).开启Apache对rewrite的支持

#LoadModule rewrite_module modules/mod_rewrite.so #去掉

2).指定Virtual host的配置文件

# Virtual hosts
# Include conf/extra/httpd-vhosts.conf #去掉

3).支持.htaccess文件

AllowOverride None替换AllowOverride all

4、Win+r 打开运行->cmd,打开DOS窗口,进入事先建好的项目目录,如zend_framework,运行zf create project HelloWorld创建名为HelloWorld的项目,

WAMP下 搭建Zend Framework(Hello World)实例

5、上述产生的项目中在D:\zend_framework\HelloWold\docs出现README.txt,打开此文件就会看到如下代码:

<VirtualHost *:80>
DocumentRoot "D:/zend_framework/HelloWold/public"
ServerName .local # This should be omitted in the production environment
SetEnv APPLICATION_ENV development <Directory "D:/zend_framework/HelloWold/public">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory> </VirtualHost>

这里将这段文字拷贝到/conf/extra/httpd-vhosts.conf文件的末尾,并稍作修改,如下:

<VirtualHost *:8099>
DocumentRoot "D:/zend_framework/HelloWorld"
ServerName 'localhost' # This should be omitted in the production environment
SetEnv APPLICATION_ENV development <Directory "D:/zend_framework/HelloWorld">
DirectoryIndex /public/index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

  此时的端口是8099,需在httpd.conf中添加Listen 8099

二、Hello World实例

1.D:\zend_framework\HelloWorld\public下的index.php代码如下 :

 <?php
error_reporting(E_ALL|E_STRICT);
date_default_timezone_set('Asia/Shanghai');
set_include_path('.' .PATH_SEPARATOR .'./library' .PATH_SEPARATOR .'./application/models/'.PATH_SEPARATOR .get_include_path());
require_once "Zend/Loader/Autoloader.php";
Zend_Loader_Autoloader::getInstance()->setFallbackAutoloader(true); //设置Zend Framework 自动载入类文件
$registry = Zend_Registry::getInstance();
//设置模板显示路径
$view = new Zend_View();
$view->setScriptPath('../application/views/scripts/index');
$registry['view'] = $view;//注册View
//设置控制器
$frontController = Zend_Controller_Front::getInstance();
$frontController->setBaseUrl('/zendframework')//设置基本路径
->setParam('noViewRenderer', true)
->setControllerDirectory('../application/controllers')
->throwExceptions(true)
->dispatch();

2.D:\zend_framework\HelloWorld\application\controllers下的IndexController.php代码如下 :

 <?php
class IndexController extends Zend_Controller_Action
{
function init()
{
$this->registry = Zend_Registry::getInstance();
$this->view = $this->registry['view'];
$this->view->baseUrl = $this->_request->getBaseUrl();
}
/*
* 输出Hello World 的Action(动作)!
*/
function indexAction()
{
//这里给变量赋值,在index.phtml模板里显示
$this->view->bodyTitle = "****Hello World****";
echo $this->view->render('index.phtml');//显示模版
}
}

3.D:\zend_framework\HelloWorld\application\views\scripts\index下的index.phtml代码如下 :

 <?php echo $this->bodyTitle; ?> <!-- 这里输出控制器里Action传过来的值:hello world -->

4.浏览器地址栏中输入:http://localhost:8099/运行后即可:

WAMP下 搭建Zend Framework(Hello World)实例

上一篇:Windows+Apache+MySQL+PHP(WAMP)环境搭建


下一篇:二维离散平稳小波分解swt2