Table of Contents
1 准备
2 本教程的程序简介
3 骨架程序
Home php教程 php手册 PHP Zend Framework2入门(一)

PHP Zend Framework2入门(一)

Jun 06, 2016 pm 07:47 PM
php zend Fake getting Started Prepare Tutorial

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 self-update
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的创建了。
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

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

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

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

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

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

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

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

CakePHP Working with Database CakePHP Working with Database Sep 10, 2024 pm 05:25 PM

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

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

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

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

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

CakePHP Logging CakePHP Logging Sep 10, 2024 pm 05:26 PM

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

See all articles