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(){}