Zend Framework教程之MVC架構的Controller用法分析,zendmvc_PHP教程

來源:互聯網
上載者:User

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用法。分享給大家供大家參考,具體如下...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.