上一节我们安装配置了Zend 框架,现在我们可以开始创建Zend Framework 项目了。本教程以创建一个保存音乐专辑的Web 简单应用为例。下面是这个web应用的简单需求:
相应地设计数据库结构如下(音乐专辑包括artist艺术家和title专辑名称):
Field name | Type | Null? | Notes |
id | integer | No | Primary key, auto increment |
artist | varchar(100) | No | |
title | varchar(100) | No |
在命令行窗口跳转到Web服务器根目录,使用zend framework 命令行工具zf命令创建一个project 项目,比如名称为zftest:
cd /var/wwwzf create project zftest
提示:
Note: This command created a web project, for more information setting up your VHOST, please see docs/READMETesting Note: PHPUnit was not found in your include_path, therefore no testing actions will be created.
原来Zend Framework 开始官方支持PHPUnit了,Pear安装PHPUnit单元测试:http://pear.phpunit.de/
sudo apt-get install php-pearsudo pear channel-discover pear.phpunit.desudo pear channel-discover pear.symfony-project.comsudo pear upgrade (Note:phpunit/PHPUnit requires PEAR Installer (version >= 1.9.4), installed version is 1.9.1)sudo pear install phpunit/PHPUnit
上面的Zend_Tool 命令行工具zf create project 创建项目时自动创建了各级目录和文件,仔细看下:
cd /var/www/zftest/library;ln -s /usr/share/ZendFramework-1.11.11-minimal/library/Zend
ls -a ../public
可以看到还有一个隐藏的.htaccess文件。比如Ubuntu 下配置apache:sudo vi /etc/apache2/sites-available/zftest
,将 docs/README.txt
中的vhost配置复制进去并保存:
<VirtualHost *:80> DocumentRoot "/var/www/zftest/public" ServerName zftest.local # This should be omitted in the production environment SetEnv APPLICATION_ENV development<Directory "/var/www/zftest/public"> Options Indexes MultiViews FollowSymLinks AllowOverride All Order allow,deny Allow from all </Directory></VirtualHost>
sudo a2ensite zftestsudo /etc/init.d/apache2 reload
修改/etc/hosts 把zftest.local 指向127.0.0.1。访问http://zftest.local (或http://localhost/zftest/public/) 就能打开显示zf图标的页面了。zftest 这个Zend Framework 项目就算创建好了。
联系客服