Home> php教程> PHP开发> body text

Detailed explanation of Zend Framework entry application examples

高洛峰
Release: 2017-01-05 10:46:53
Original
1151 people have browsed it

The example in this article describes the Zend Framework entry-level application. Share it with everyone for your reference, the details are as follows:

.htaccess file

.htaccess file is used to implement URL reset, that is, when the user accesses a resource, it will be redirected to the specified under the file.

Code example:

RewriteEngine on RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php
Copy after login

Among them, line 1 means that the reset engine is turned on, and line 2 means that when accessing other than js, ico, gif, jpg, png, css file,

will be reset to the index.php file.

Note:

This rewrite rule can only be used on the Apache server and requires the use of the Apache redirection module. To be effective, the function must be enabled. Confirm that

#LoadModule rewrite_module modules/mod_rewrite.so
Copy after login

under Apache's httpd.conf configuration file is turned on, that is, remove the # sign.

Automatically generate directory

After decompressing the downloaded zend, there will be two core directories, one is library and the other is bin. There is a zf.bat file under bin that can be used to intelligently generate the Zend Framework directory structure.

But certain configuration must be done before use, that is, the configuration of environment variables. Only in this way can its commands be called directly. Otherwise the build command cannot be called.

1. Configure environment variables

The configuration process is as shown in the figure:

Zend Framework入门应用实例详解

After adding the path, you can directly enter the "small Black box", that is, the instruction is directly called in CMD. Two are configured here, one is the bin directory under zend, and the other is the php directory under xampp. Because the instructions need to use some files in these two directories.

2. Whether the test is successful

Zend Framework入门应用实例详解

#The above message appears, indicating that the environment variable configuration is successful.

3. Execute the generation command

zf create project zfdemo
Copy after login

Zend Framework入门应用实例详解

At this time, a project directory will be generated, as shown in the above prompt. There will be a directory zfdemo under the C drive.

Zend Framework入门应用实例详解

4. Copy the information in the directory to the project folder and test

The entry file here is under public

So in Enter the address "http://localhost/zendDemo/public/"

Note: The name of the project is zendDemo

If nothing goes wrong, you will see the successful execution result. . As shown in the figure below:

Zend Framework入门应用实例详解

#Note: Because I rewrote the default view file content, all I saw were the four words "Hello World".

Transformation

1. Create your own controller

Create a controller named SelfController.php in the application/controllers/ directory and enter the following code.


        
Copy after login

The above code defines a SelfController class, and defines the selfAction() method and myAction() method in this class.

2. Create the corresponding view file

Create the self.phtml file in the application/views/scripts/self/ directory, the code is as follows:

   t tle>self方法的显示视图  

self方法的显示视图

Copy after login


Continue to create the my.phtml file in the same directory, the code is as follows:

   my方法的显示视图 

my方法的显示视图

Copy after login


3. Testing and Execution

You should first understand how Zend Framework handles HTTP requests. By default, the first part of the URL is mapped to a controller, and the second part is mapped to the Action method in the controller class.

The execution result is shown in the figure below:

Zend Framework入门应用实例详解

I hope this article will be helpful to everyone’s PHP program design based on the Zend Framework framework.

For more detailed Zend Framework introductory application examples and related articles, please pay attention to the PHP Chinese website!

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
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!