PHP Zend Framework2入门(一)
1 准备 本教程假设你最少运行PHP5.3.23,安装了apazhe WEB server 和MySQL.MySQL。访问MySQL用的是PDO扩展。你必须确定apache配置成了支持.htaccess 文件。这可以通过在你的httpd.conf文件中改变设置: AllowOverride None 为 AllowOverride FileInfo 做到。
1 准备
本教程假设你最少运行PHP5.3.23,安装了apazhe WEB server 和MySQL.MySQL。访问MySQL用的是PDO扩展。你必须确定apache配置成了支持.htaccess 文件。这可以通过在你的httpd.conf文件中改变设置:AllowOverride None
为
AllowOverride FileInfo
做到。 如果你没有把mod_rewrite和.htaccess配置正确,那么在本教程中你将除了主页外导航不到其它任何页面。
注:
如果你使用的是PHP5.4+,你可要以直接使用PHP内置的web server用于开发,而不是Apache。
2 本教程的程序简介
我们要建的程序是一个简单的清单系统,它显示我们所拥有的音乐专辑。主页上列出我们的专辑并允许添加、修改、和删除CD。我们的网站一共需要四个页面。1) 专辑列表 列出专辑并提供链接修改和删除专辑。也提供了链接来添加新专辑。
2) 添加专辑 提供一个form添加新专辑。
3) 修改专辑 提供一个form用于修改专辑。
4) 删除专辑 确认用户真的想删除专辑,然后删除它。
我们还需要把我们的数据存到数据库中。我们只需要一个表,它有这些字段:
1) id 类型:integer; 可为空:No; 主键,自增长。
2) artist 类型:varchar(100); 可为空:No
3) title 类型:varchar(100); 可为空:No
3 骨架程序
为了创建我们的程序,我们需要从ZendSkeletonApplication开始。ZendSkeletonApplication在github上可下载到。使用Composer(http://getcomposer.org) 来创建一个基于Zend Framework 的新工程,命令行如下:
php composer.phar create-project --repository-url="https://packages.zendframework.com" zendframework/skeleton-application path/to/install
php composer.phar update
注:
另一个安装ZendSkeletonApplication 的方式是使用github。到网站https://github.com/zendframework/ZendSkeletonApplication ,点击“Zip”按钮。将下载一个文件,名字差不多是ZendSkeletonApplication-master.zip。解压这个文件并命名解出的文件夹为:zf2-tutorial。ZendSkeletonApplication被设置为使用Composer 来解决它所依赖的东西们。其实当前它只依赖于Zend Framework 2。
要安装Zend Framework 2到我们的程序中,我们只需进入到zf2-tutorial 文件夹,然后简单的搞一下:
php composer.phar install
php composer.phar update
Installing dependencies from lock file
- Installing zendframework/zendframework (dev-master)
Cloning 18c8e223f070deb07c17543ed938b54542aa0ed8
Generating autoload files
注:
如果你看到这些信息:
[RuntimeException]
The process timed out.
那么你的下载已经变得很慢了,composer超时了。要避免这个问题,不要再运行:
php composer.phar install
php composer.phar update
而是运行:
COMPOSER_PROCESS_TIMEOUT=5000 php composer.phar install
COMPOSER_PROCESS_TIMEOUT=5000 php composer.phar update
注:
在windows下使用wamp的人们啊,你们需要这样搞:
1) 安装composer windows版,执行下面的命令检查是否正确安装了composer:
composer
2) 安装windows版 git。
3) 安装zf2。使用命令:
composer create-project --repository-url="https://packages.zendframework.com" -s dev zendframework/skeleton-application path/to/install
现在我们可以进行web server的创建了。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Validator can be created by adding the following two lines in the controller.

Logging in CakePHP is a very easy task. You just have to use one function. You can log errors, exceptions, user activities, action taken by users, for any background process like cronjob. Logging data in CakePHP is easy. The log() function is provide
