(以下的环境是windows下,ZF1.9.5版本)
1 下周zf的源码库。并配置bin文件夹为系统变量。
2 查看ZF的版本,cmd下,运行:
zf show version
3 进入cmd,在需要建立zf project的目录内,运行:
zf.bat create project quickstart
4 需要把zend的 library 文件夹下的 zend 文件夹copy 到 相应项目的 library 下。
5 环境的定义:是在.htaccess中定义的,SetEnv APPLICATION_ENV development 。如果没有定义的话,则默认是production环境。
6 layout的设置:
A 配置文件添加
; application/configs/application.ini
; Add to [production] section:
resources.view[] =
B 引导程序(Bootstrap)中配置默认的layout的通用参数。
Bootstrap.php
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><?php
// application/Bootstrap.php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initDoctype()
{
$this->bootstrap('view');
$view = $this->getResource('view');
$view->doctype('XHTML1_STRICT');
}
}
C 建立layout文件。
layout.phtml
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><?php
// application/layouts/scripts/layout.phtml
echo $this->doctype() ?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Zend Framework Quickstart Application</title>
<?php echo $this->headLink()->appendStylesheet('/css/global.css') ?>
</head>
<body>
<div id="header" style="background-color: #EEEEEE; height: 30px;">
<div id="header-logo" style="float: left">
<b>ZF Quickstart Application</b>
</div>
<div id="header-navigation" style="float: right">
<a href="<?php echo $this->url(
array('controller'=>'guestbook'),
'default',
true) ?>">Guestbook</a>
</div>
</div>
<?php echo $this->layout()->content ?>
</body>
</html>
7 创建控制器:
zf create controller posts
8 创建view:
zf create action view posts
9 创建action:
zf create action edit posts
10 数据库配置
; application/configs/application.ini
resources.db.adapter = "PDO_MYSQL"
resources.db.params.host = localhost
resources.db.params.port = 3306
resources.db.params.username = root
resources.db.params.password =
resources.db.params.dbname = zf_demo
resources.db.charset = utf8