Home > Backend Development > PHP Tutorial > Summary of Zend Framework introductory knowledge points, zendframework_PHP tutorial

Summary of Zend Framework introductory knowledge points, zendframework_PHP tutorial

WBOY
Release: 2016-07-12 08:56:35
Original
764 people have browsed it

A summary of Zend Framework introductory knowledge points, zendframework

This article summarizes and analyzes the Zend Framework introductory knowledge points. Share it with everyone for your reference, the details are as follows:

zend framework is an implementation of the MVC pattern. 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 simple:

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

Copy after login

What should be explained here is that you cannot use new to obtain a Zend_Controller_Front. You can only call the getInstance method 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 codes are:

$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 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, a simple

Class IndexController extends Zend_Controller_Action
{
 function IndexAction()
 {
 }
}

Copy after login

You need to create an index directory accordingly, and create an index.phtml template under 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.

You can write:

$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

You can get it like this when using:

$view=Zend_Registry::get("view");

Copy after login

3. When you first come into contact with it, 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 enough for general 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 use your class name to search for the table in the database by default. Don’t forget to specify 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

Readers who are interested in more zend-related content can check out the special topics of this site: "Zend FrameWork Framework Introductory Tutorial", "php Excellent Development Framework Summary", "Yii Framework Introduction and Summary of Common Techniques", "ThinkPHP Introductory Tutorial" , "php object-oriented programming introductory tutorial", "php mysql database operation introductory tutorial" and "php common database operation skills summary"

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

Articles you may be interested in:

  • Zend Framework Tutorial: Zend_Db_Table_Row Usage Example Analysis
  • Zend Framework Tutorial: Zend_Db_Table Usage Detailed Explanation
  • Zend Framework Cache Simple usage example
  • Zend Framework basic page layout analysis
  • Zend Framework connection Mysql database instance analysis
  • Zend Framework smarty usage example detailed explanation
  • Zend Framework tutorial Detailed explanation of Application usage examples
  • Summary of precautions related to Zend Framework custom Helper class
  • Overview of Bootstrap class usage in Zend Framework tutorial
  • Detailed explanation of Autoloading usage in Zend Framework tutorial
  • Zend Framework Tutorial: Controller Usage Analysis of MVC Framework
  • Zend Framework Tutorial: Zend_Db_Table_Rowset Usage Example

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1111886.htmlTechArticleA summary of Zend Framework introductory knowledge points, zendframework This article summarizes and analyzes the Zend Framework introductory knowledge points. Share it with everyone for your reference, the details are as follows: zend framework is an MVC model...
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template