Home Backend Development PHP Tutorial Summary of Zend Framework introductory knowledge points

Summary of Zend Framework introductory knowledge points

Dec 26, 2016 pm 03:48 PM

This article summarizes and analyzes the introductory knowledge points of Zend Framework. I share it with you for your reference, as follows:

zend framework is an implementation of the MVC pattern. If you want to get started quickly, just look at the Zend_Controller Zend_View part.

1.Zend_Controller part. The most important class is Zend_Controller_Front. The classic code to use it is very simple:

$front=Zend_Controller_Front::getInstance();
$front-> setControllerDirectory("./app/controllers");
$front->dispatch();
Copy after login


What should be noted here is that you cannot use new to get a Zend_Controller_Front. The getInstance method can only be called to return an instance (my zend_framework uses 1.01). The controllers directory I specified here is under the app folder under the www document root directory. Generally speaking, apps should not be placed in the document root directory - the so-called security issue: if the configuration is not strict, the files in the www document root directory may be visible to visitors. Generally, it should be placed in another directory. For example, if it is placed at the same level as the document root directory, you can use:

$front->setControllerDirectory("../app/controllers")
Copy after login


There is one more ". ". Relative paths are used here. You can specify other directories using their full path names. For example:

$front->setControllerDirectory("E: /server/app/controllers")
Copy after login


This part is included in the index. in php. Under the correct configuration, any request will be redirected by the rewrite function to this $front, which is the front-end controller Zend_Controller_Front instance. All authentication and other processing must be processed before dispatch.

2.Zend_View common code is:

$view=new Zend_View();
Zend_Registry::set("view".$view);
Copy after login


The directory structure recommended by Zend_Framework is adopted by default. That is, views and controllers models are the same Levels are all in the application directory. There are three sibling directories under views: scrīpts helpers filters. In this way, when you define a Controller, you have to create a new directory under scrīpts to store the templates subordinate to the Controller. For example, for a simple

Class IndexController extends Zend_Controller_Action
{
 function IndexAction()
 {
 }
}
Copy after login


, you need to create an index directory in it accordingly, and create an index.phtml template in the index directory. If you create another function addAction() under IndexController, you have to create a new add.phtml in index. If you have another UserController, you must have a corresponding user directory under scrīpts. These *.phtml files are similar to html files and define how the content you output is displayed. You can simply leave it blank. But it cannot be left out, otherwise it will prompt "error" invalid Controller... This is because the default ErrorController has already been registered. The default ErrorController will be called when the front-end controller cannot find the corresponding controller distribution.

Sometimes we don’t want to use the default directory structure or the default phtml type view template. At this time we can use

$view->setParam ("noViewRanderer",true);
Copy after login


to cancel the default phtml type directory setting. Use

$view->setParam ("noErrorHandler",true);
Copy after login


to write in the default ErrorController. Use

$view->setscrīptPath ("./app/views");
Copy after login


to set the location of your template. This is useful when using smarty templates.

can be written like this:

$view=new Zend_View_Smarty();
$view->setParam("noViewRanderer",true);
$view->setParam("noErrorHandler",true);
$view->setscrīptPath("./app/views");
Zend_Registry::set("view".$view);
Copy after login


can be obtained like this when using:

$view=Zend_Registry::get("view");
Copy after login


3. When you first come into contact, the model can be simply understood as a data object. For those who operate the database, you can generally directly inherit the Zend_Db_Table class. This class is very encapsulated and is generally sufficient for use:

class data extends Zend_Db_Table
{
 protected $_name="data";
}
Copy after login


You only need to specify the name of the table. Of course, you don’t need to specify it explicitly. In this case, zendf will search the database with your class name by default. table in . Don’t forget to specify the defaultAdapter for Zend_Db_Table:

$config = new Zend_Config_Ini('./application/config.ini', 'general');
$db = Zend_Db::factory($config->db->adapter, $config->db->config->toArray());
Zend_Db_Table::setDefaultAdapter($db);
Copy after login


config.ini is similar to [general]

db.adapter = PDO_MYSQL
db.config.host = localhost
db.config.username = rob
db.config.password = 123456
db.config.dbname = zftest
Copy after login


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

For more articles related to Zend Framework introductory knowledge points, 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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

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)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

How to debug CLI mode in PHPStorm? How to debug CLI mode in PHPStorm? Apr 01, 2025 pm 02:57 PM

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

Explain the concept of late static binding in PHP. Explain the concept of late static binding in PHP. Mar 21, 2025 pm 01:33 PM

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

How to send a POST request containing JSON data using PHP's cURL library? How to send a POST request containing JSON data using PHP's cURL library? Apr 01, 2025 pm 03:12 PM

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

See all articles