Zend Framework Introduction Application Example Detailed _php example

Source: Internet
Author: User
Tags zend zend framework

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

ZF Create Project Zfdemo

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.