Introduction to ZendFramework

Source: Internet
Author: User
Tags smarty template
This article summarizes and analyzes the ZendFramework entry point. I would like to share it with you for your reference. The zendframework is an implementation of the MVC mode. To get started quickly, just look at Zend_ControllerZend_View. 1. Zend_Controller. The most important class is Zend_Controller_Front. Use its

This article summarizes and analyzes the Zend Framework entry point. I would like to share it with you for your reference. The zend framework is an implementation of the MVC mode. To get started quickly, just read the Zend_Controller Zend_View section. 1. Zend_Controller. The most important class is Zend_Controller_Front. Use its

This article summarizes and analyzes the Zend Framework entry point. We will share this with you for your reference. The details are as follows:

Zend framework is an implementation of the MVC mode. To get started quickly, you just need to check Zend_Controller Zend_View.

1. Zend_Controller. 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();

It should be noted 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 ). Here, the controllers directory I specified is under the app folder under the root directory of the www document. In general, apps should not be placed under the root directory of the document-the so-called security problem: If the configuration is not strict, the files in the root directory of the www document may be visible to visitors. It is usually placed in another directory. For example, if it is placed in the same level as the document root directory, you can use:

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

A "." is added ".". The relative path is used here. You can use the full name of the path to specify other directories. For example:

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

This part is included in index. In php. With the correct configuration, any request will be redirected from the rewrite function to this $ front-end controller Zend_Controller_Front instance. All authentication processes must be pre-processed in dispatch.

2. Common Zend_View code:

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

The directory structure recommended by Zend_Framework is used by default. That is, views and controllers models are both under the application directory. Under views, there are three directories of the same level, scr javaspts helpers filters. In this way, when you define a Controller, you have to create a directory under scr ī pts to store the template of the Controller. For example

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

You need to create an index DIRECTORY and an index. phtml Template under the index DIRECTORY. If you create another function addAction () under IndexController, you have to create an add. phtml file in index. If you have another UserController, you need to have a user directory under scr ī pts. These *. phtml files are similar to html files and define how your output content is displayed. Simply leave the blank space. But it cannot be absent. Otherwise, the system will prompt "error" invalid Controller... this is because the default ErrorController is already registered. When the front-end controller cannot find the corresponding controller for distribution, the default ErrorController is called.

Sometimes we do not want to use the default directory structure or the default phtml type view template. In this case, we can use

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

To cancel the default phtml directory settings. Use

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

In the default ErrorController. Use

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

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

This can be written as follows:

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

You can obtain the following information during use:

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

3. When I first came into contact with the model, I could simply understand it as a data object. For database operations, the class Zend_Db_Table can be directly inherited. This class is well encapsulated and is generally enough:

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

You only need to specify the table name. Of course, you can leave it unspecified. zendf searches for tables in the database by default using your class name. Do not 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);

Config. ini is similar to [general]

db.adapter = PDO_MYSQLdb.config.host = localhostdb.config.username = robdb.config.password = 123456db.config.dbname = zftest

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.