Home php教程 PHP开发 Detailed explanation of Zend Framework entry application examples

Detailed explanation of Zend Framework entry application examples

Jan 05, 2017 am 10:46 AM

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.

<?php
class SelfController extends Zend_Controller_Action{
  public function selfAction(){
    //self方法
  }
  public function myAction(){
    //my方法
  }
}
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:

<html>
<head>
  <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
   t tle>self方法的显示视图</title>
</he  >
  <h1> self方法的显示视图</h1>
</body
Copy after login


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

<html>
<head>
  <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
  <title>my方法的显示视图</title>
</head>
<body>
  <h1>my方法的显示视图</h1>
</body>
</html>
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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)