ZendFramework entry (1)-quick start, read ZendFramework entry (1)-quick start, 1. Install and download the latest version from the ZendFramework webpage. After decompression, copy the entire directory to an ideal place, such as/php/library/Zend. Open the php. Ini file and confirm that the path containing the Zend directory is in
1. Install
Download the latest version from the Zend Framework webpage. After decompression, copy the entire directory to an ideal place, such as/php/library/Zend.
Open the php. ini file and confirm that the path containing the Zend directory is defined in include_path. The preceding configuration is used as an example. php. ini should have entries similar to the following:
Export de_path = ".:/php/library"
Note: The writing method in Windows is slightly different. It should be similar to include_path = ".; C: \ php \ library"
The initial installation is that simple. Some components of Zend Framework use some additional modules of php. For specific requirements, refer to here.
2. Directory structure of the project
If your project does not contain multiple modules, you can use the following directory structure:
Application/controllers/IndexController. phpmodels/views/scripts/index. phtmlhelpers/filters/html /. htaccessindex. php if your project contains multiple modules (such as blogs, communities, and so on), we recommend that you use a modular directory structure.
3. Root directory of the webpage
The root directory of the webpage should point to the html folder in the preceding 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 preceding configuration is for apache. For other servers, see here.
5. Bootstrap program
Edit the html/index. php file and enter the following code:
The default routing rule of Zend Framework is http: // domain name/controller name/action (method) name. For example:
It will be parsed to the controller named User and the show method defined in the controller. If this method is not defined, it is converted to the index method by default.
Note: in the code, the Controller name must be followed by the Controller name, and the Action name must be followed by 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. phtml and enter:
My first Zend Framework AppHello, World!8. Error controller
By default, the error handling plug-in of Zend Framework is registered. It requires an error controller to handle the error. The default error control processing is assumed to be ErrorController and the errorAction defined in it.
Edit application/controllers/ErrorController. php and 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. phtml and enter:
ErrorAn error occurred
An error occurred; please try again later.
9. 运行
好,现在运行网站。在浏览器中键入下面三个地址,得到的结果应该是一样的——就是最最常见的“Hello, World!“。
http://域名
http://域名/index
http://域名/index/index
如果是这样,那么恭喜你!