ZendFramework tutorial-Controller Usage Analysis of MVC Framework-php instance

Source: Internet
Author: User
Tags zend framework
This article mainly introduces the Controller usage of the MVC Framework in the ZendFramework tutorial. It briefly analyzes the basic structure of the MVC Framework and the simple usage of the Controller, for more information about the Controller usage of the MVC Framework in the Zend Framework tutorial, see the following section. We will share this with you for your reference. The details are as follows:

Here is a brief introduction to the basic use of Controller in MVC mode.

Basic instance:

Root @ coder-671T-M:/www/zf_demo1/application # tree.
├ ── Bootstrap. php
── Configs
│ ── Application. ini
├ ── Controllers
│ ── ErrorController. php
│ ── IndexController. php
── Models
── Views
── Helpers
── Scripts
── Error
│ ── Error. phtml
── Index
── Index. phtml

IndexController. php

<?phpclass IndexController extends Zend_Controller_Action{  public function init()  {    /* Initialize action controller here */  }  public function indexAction()  {    // action body  }}

Rules:

1. The Controller is usually stored in the/application/controllers directory of the application.
You can customize the path in the following ways:

Zend_Controller_Front::run('/path/to/app/controllers');

You can also customize the path in the following ways:

// Set the default controller directory:$front->setControllerDirectory('../application/controllers');// Set several module directories at once:$front->setControllerDirectory(array(  'default' => '../application/controllers',  'blog'  => '../modules/blog/controllers',  'news'  => '../modules/news/controllers',));// Add a 'foo' module directory:$front->addControllerDirectory('../modules/foo/controllers', 'foo');

By default, it is stored in the default directory.

2. The file name and class name are the same
3. The class name ends with the Controller and inherits Zend_Controller_Action
4. the first letter of the class name is in upper case and complies with the camper style. Profit NewsListControlle
4. The file name ends with Controller. php.
5. The Controller initialization can be completed in the init method.

public function init(){}

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.