原文:
http://packages.zendframework.com/docs/latest/manual/en/user-guide/skeleton-application.html
译者注:
原来以为这个会和上面的项目直接有衔接,其实是基于ZF2做的一个很简单的web应用的结构,主要是为了方便用户理解一般ZF2项目的框架结构。所以为什么要用“Skeleton”这个词。
为了能够建立我们的应用,我们会从 ZendSkeletonApplication(Zend 骨干应用,能够从github获取)开始 建立应用。可以去 https://github.com/zendframework/ZendSkeletonApplication 点击“zip”按钮打包下载源代码。你会获取到类似“zendframework-ZendSkeletonApplication-zfrelease-2.0.0beta5-2-gc2c7315.zip”这样的文件。
解压缩文件,然后放到你配置好的虚拟机的文件夹下面zf2-tutorial(当然,你也可以使用其它的名字)。
ZendSkeletonApplication 是使用Composer(http://getcomposer.org)创建并去除了依赖性,实际上主要依赖ZF2。
我们简单的输入以下命令来安装ZF2框架:
php composer.phar self-update
php composer.phar install
通过zf2-tutorial文件夹,过一会。你可能会看到如下输出:
Installing dependencies from lock file
- Installing zendframework/zendframework (dev-master)
Cloning 18c8e223f070deb07c17543ed938b54542aa0ed8
Generating autoload files
注意:你可能看到如下的信息:
[RuntimeException]
The process timed out.
那是因为可能你的网速太慢了导致不能下载太快,所以为了防止这样,将如下命令:
php composer.phar install
替代为:
COMPOSER_PROCESS_TIMEOUT=5000 php composer.phar install
然后我们就可以进入虚拟主机中。
虚拟主机配置
为了能够通过 http://zf2-tutorial.localhost 这样的路径来访问你的 zf2-tutorial/public 文件夹,你需要配置你的虚拟主机。
一般配置虚拟主机在 httpd.conf 或者 extra/httpd-vhosts.conf 文件中。如果你使用 extra/httpd-vhosts.conf 文件的话,记住需要在 httpd.conf 包括进去。一些Linux发布版(如:Ubuntu)Apache的配置文件放在/etc/apache2文件中,并且/etc/apache2/sites-enabled单独配置一个虚拟机,如果这样你需要添加路径 /etc/apache2/sites-enabled/zf2-tutorial 进虚拟机。
确保 NameVirtualHost 及 80 端口都要定义下来,大致的配置文件如下:
<VirtualHost *:80>
ServerName zf2-tutorial.localhost
DocumentRoot /path/to/zf2-tutorial/public
SetEnv APPLICATION_ENV "development"
<Directory /path/to/zf2-tutorial/public>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
同时确保你的操作系统上的Hosts重定向 http://zf2-tutorial.localhost 到 127.0.0.1。Linux上是“/etc/hosts”,Windows上在“c:\windows\system32\drivers\etc\hosts”上。
127.0.0.1 zf2-tutorial.localhost localhost
然后访问的话有如下页面:
为了测试你的.htaccess文件是否工作,如果访问 http://zf2-tutorial.localhost/1234 你会得到如下页面:
如果你是看到一个标准的Apache 4040错误页面,你需要修正你的.htaccess页面。如果你是使用IIS服务器的话,你的URL转发规则如下:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.*$ index.php [NC,L]
你现在就开始使用一个骨干系统并且我们开始添加一些其它的特征去你的系统。