This example describes the Zend Framework entry application. Share to everyone for your reference, specific as follows:
. htaccess file
The. htaccess file is used to implement a URL reset, that is, when a user accesses a resource, it is relocated to the specified file.
code example:
Rewriteengine on
rewriterule!\. ( JS|ICO|GIF|JPG|PNG|CSS) $ index.php
Where line 1 indicates that the reset engine is open and line 2 means that when accessing files other than JS, ico, GIF, JPG, PNG, CSS,
will be reset to the index.php file.
Note:
This overriding rule can only be used for the Apache server, which requires the Apache redirection module. If you want to be effective, turn on the function. Verify that the Apache httpd.conf configuration file
#LoadModule Rewrite_module modules/mod_rewrite.so
Open, that is to remove the # number.
Automatically generate catalogs
After the download of the Zend decompression, there will be two core directories, one is the library, one is bin. Below the bin there is a zf.bat file that can be used to intelligently generate the Zend Framework directory structure.
However, before use must do a certain configuration, that is, the configuration of environment variables. This allows the command to be invoked directly. The build command cannot be invoked otherwise.
I. Configuring Environment variables
The configuration process is as shown in the figure:
After adding path, you can directly invoke instructions in the "Small black box", which is cmd. There are two configured, one is Zend under the bin directory, one is xampp under the PHP directory. Because the instructions need to use some of the files in these two directories.
Second, the test is successful
The information above shows that the environment variable configuration was successful.
Third, the implementation of the build instructions
At this point, an engineering directory will be generated, as shown in the above hints. There will be a directory Zfdemo under C disk.
Iv. Copy the information from the directory to the project folder and test
The entry file here is under public
So enter the address "http://localhost/zendDemo/public/" in the browser
Note: The name of the project is Zenddemo
If nothing goes wrong, you will see the results of successful execution. As shown in the following illustration:
Note: Because I rewrite the default view file content, I see "Hello World" four words.
Reform
First, create your own controller
Create a controller named selfcontroller.php under the application/controllers/directory and enter the following code.
<?php
class Selfcontroller extends zend_controller_action{public
function selfaction () {
//self method
}
Public Function myaction () {
//my method
}
}
The preceding code defines a Selfcontroller class and defines the Selfaction () method and the Myaction () method in the class.
Second, create the corresponding view file
Create the self.phtml file in the application/views/scripts/self/directory with the following code:
Continue to create the my.phtml file in the same directory with the following code:
III. Testing and implementation
You should first understand how the Zend Framework handles HTTP requests. By default, the first part of the URL maps to a controller, and the second part maps to the action method in the Controller class.
The results of the execution are shown in the following illustration:
More interested in Zend related content readers can view the site topics: "The introduction of the Zend Framework frame", "PHP Excellent Development Framework Summary", "Yii framework Introduction and common skills Summary", "thinkphp Introductory Course", "PHP object-oriented Programming Program , "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation Skills Summary"
I hope this article will help you with the PHP program design based on the Zend Framework.