Zend Framework教程之MVC架構的Controller用法分析,zendmvc
本文講述了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
<?phpclass 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相關內容感興趣的讀者可查看本站專題:《Zend FrameWork架構入門教程》、《php優秀開發架構總結》、《Yii架構入門及常用技巧總結》、《ThinkPHP入門教程》、《php物件導向程式設計入門教程》、《php+mysql資料庫操作入門教程》及《php常見資料庫操作技巧匯總》
希望本文所述對大家PHP程式設計有所協助。
您可能感興趣的文章:
- Zend Framework教程之Autoloading用法詳解
- Zend Framework教程之Resource Autoloading用法執行個體
- Zend Framework教程之路由功能Zend_Controller_Router詳解
- Zend Framework教程之Zend_Controller_Plugin外掛程式用法詳解
- Zend Framework教程之響應對象的封裝Zend_Controller_Response執行個體詳解
- Zend Framework教程之請求對象的封裝Zend_Controller_Request執行個體詳解
- Zend Framework教程之動作的基類Zend_Controller_Action詳解
- Zend Framework教程之分發器Zend_Controller_Dispatcher用法詳解
- Zend Framework教程之前端控制器Zend_Controller_Front用法詳解
- Zend Framework教程之視圖組件Zend_View用法詳解
- Zend Framework教程之Loader以及PluginLoader用法詳解
http://www.bkjia.com/PHPjc/1106888.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1106888.htmlTechArticleZend Framework教程之MVC架構的Controller用法分析,zendmvc 本文講述了Zend Framework教程之MVC架構的Controller用法。分享給大家供大家參考,具體如下...