Home > php教程 > PHP开发 > Getting Started with Zend Framework (1)—Getting Started Quickly

Getting Started with Zend Framework (1)—Getting Started Quickly

黄舟
Release: 2016-12-17 10:24:36
Original
1124 people have browsed it

1. Installation

Download the latest version from the Zend Framework website. After unzipping, copy the entire directory to an ideal location, such as: /php/library/Zend.

Open the php.ini file and confirm that the path containing the Zend directory is defined in include_path. Taking the above configuration as an example, there should be entries similar to the following in php.ini:

include_path = ".:/php/library"

Note: The writing method under Windows is slightly different and should be similar to include_path = ".; C:phplibrary"

The initial installation is that simple. Some components of Zend Framework use some additional modules of PHP. Please refer here for specific requirements.

2. Project directory structure

If your project does not contain multiple modules, you can use the following directory structure:

application/controllers/IndexController.phpmodels/views/scripts/index/index.phtmlhelpers/filters/html /.htaccessindex.php If your project will contain multiple modules (for example: blog, community, etc.), then it is recommended to use a modular directory structure.

3. The root directory of the web page

The root directory of the web page should point to the html folder in the above directory structure.

4. Rewrite rules

Edit the html/.htaccess file and add the following two lines:

RewriteEngine onRewriteRule !.(js|ico|gif|jpg|png|CSS)$ index.php Note: The above is for apache Configuration. If it is another server, please refer to here.

5. Bootloader

Edit the html/index.php file and enter the following code:

Zend Framework’s default routing rule is http://domain name/controller name/action (method) name. For example:

http://example.com/user/show will be parsed to the controller named User and the show method defined in the controller. If this method is not defined, it defaults to the index method.

Note: In the code, Controller should be added after the controller name, and Action should be added after the action name.

Edit the application/controllers/IndexController.php file and enter:
/**Zend_Controller_Action*/
require_once'Zend/Controller/Action.php';

classIndexControllerextendsZend_Controller_Action
{
  public functionindexAction()
{
}
}

7. View (page) script

Edit application/views/scripts/index/index.phtml, enter:

My first Zend Framework App

Hello, World!

8. Error Controller

By default, the Zend Framework error handling plug-in is registered. It requires an error controller to handle errors. The default error control handling is assumed to be the ErrorController and the errorAction defined in it.

Edit application/controllers/ErrorController.php, enter:
/**Zend_Controller_Action*/
require_once'Zend/Controller/Action.php';

classErrorControllerextendsZend_Controller_Action
{
  public functionerrorAction()
{
}
}

The following is the corresponding view script. Edit application/views/scripts/error/error.phtml and enter:

< title>Error

An error occurred

An error occurred; please try again later.

9. Run

Okay, now run the website. Type the following three addresses into the browser, and the result should be the same - the most common "Hello, World!".

http://domain name
http://domain name/index
http://domain name/index/index
If this is the case, then congratulations!

The above is the introduction to Zend Framework (1)-quick start. For more related articles, please pay attention to the PHP Chinese website (www.php.cn)!


Related labels:
source:php.cn
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template