1. Installation
Download the latest version from the Zend Framework web page. 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:php library"
The initial installation is that simple. Some components of Zend Framework will 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 If your project contains multiple modules (for example: blog, community, etc.), 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 the configuration for apache. If it is another server, please refer to here.
5. Edit the html/index.php file in the boot program
and enter the following code:
<?phprequire_once'Zend/Controller/Front.php';$rootPath = dirname(dirname(__FILE__));Zend_Controller_Front::run($rootPath .' /application/controllers');The function of the above code is to instantiate the front controller (Front Controller) and run it. 6. Default Action Controller
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:
<?php
/** Zend_Controller_Action */
require_once'Zend/Controller/Action.php';
classIndexControllerextendsZend_Controller_Action
{
public functionindexAction()
{
}
}
7. Edit the view (page) script
application/views/scripts/index/index.phtml, enter:
<!DOCTYPE htmlPUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"" http://www.w3 .org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title >My first Zend Framework App</title></head><body><h1>Hello, World!</h1></body></html>8. Error controller
By default, Zend Framework error handling Plugins are 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 and enter:
<?php
/** 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:
<!DOCTYPE htmlPUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"" http://www.w3.org/TR/xhtml1/DTD /xhtml1-strict.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Error</title></ head><body><h1>An error occurred</h1><p>An error occurred; please try again later.</p></body></html>9. Running
well, 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 so, congratulations!