This article describes the Controller usage of the MVC framework in the Zend Framework tutorial. Share it with everyone for your reference, the details are as follows:
Here is a brief introduction to the basic use of Controller in the MVC model.
Basic usage examples:
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
<?php class IndexController extends Zend_Controller_Action { public function init() { /* Initialize action controller here */ } public function indexAction() { // action body } }
Rules:
1. Usually Controller is stored in the /application/controllers directory of the application.
The path can be customized via:
Zend_Controller_Front::run('/path/to/app/controllers');
Or customize the path via:
// 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 can be stored in the default directory.
2. The file name and class name are the same
3. The class name ends with Controller and inherits Zend_Controller_Action
4. Capitalize the first letter of the class name and follow the camel case style. ProfitNewsListControlle
4. The file name ends with Controller.php
5. The initialization work of Controller can be completed in the init method
public function init() { }
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 in PHP programming.