這篇文章給大家分享的是有關Zend Framework之MVC框架的Controller怎么用的內容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。
具體如下:
這里簡單講講MVC模式中Controller的基本使用方法。
基本使用實例:
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 } }
規則:
1.通常Controller存放在應用的/application/controllers目錄下。
可以通過以下方式自定義路徑:
Zend_Controller_Front::run('/path/to/app/controllers');
或者通過以下方式自定義路徑:
// 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');
默認情況下存放在默認的目錄即可。
2.文件名和類名相同
3.類名以Controller結尾,并且繼承Zend_Controller_Action
4.類名第一個字母大寫,遵守駝峰風格。利潤NewsListControlle
4.文件名以Controller.php結尾
5.Controller的初始化工作可以在init方法中完成
public function init() { }
感謝各位的閱讀!關于“Zend Framework之MVC框架的Controller怎么用”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,讓大家可以學到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。