Zend Framework教程之MVC框架的Controller用法分析
本文講述了Zend Framework教程之MVC框架的Controller用法。分享給大家供大家參考,具體如下:
這里簡(jiǎn)單講講MVC模式中Controller的基本使用方法。
基本使用實(shí)例:
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
}
}
規(guī)則:
1.通常Controller存放在應(yīng)用的/application/controllers目錄下。
可以通過(guò)以下方式自定義路徑:
Zend_Controller_Front::run('/path/to/app/controllers');
或者通過(guò)以下方式自定義路徑:
// 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');
默認(rèn)情況下存放在默認(rèn)的目錄即可。
2.文件名和類名相同
3.類名以Controller結(jié)尾,并且繼承Zend_Controller_Action
4.類名第一個(gè)字母大寫,遵守駝峰風(fēng)格。利潤(rùn)NewsListControlle
4.文件名以Controller.php結(jié)尾
5.Controller的初始化工作可以在init方法中完成
public function init()
{
}
更多關(guān)于zend相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Zend FrameWork框架入門教程》、《php優(yōu)秀開發(fā)框架總結(jié)》、《Yii框架入門及常用技巧總結(jié)》、《ThinkPHP入門教程》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》、《php+mysql數(shù)據(jù)庫(kù)操作入門教程》及《php常見(jiàn)數(shù)據(jù)庫(kù)操作技巧匯總》
希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。
- Zend Framework連接Mysql數(shù)據(jù)庫(kù)實(shí)例分析
- 解析如何使用Zend Framework 連接數(shù)據(jù)庫(kù)
- zend framework配置操作數(shù)據(jù)庫(kù)實(shí)例分析
- Zend Framework框架教程之Zend_Db_Table_Rowset用法實(shí)例分析
- Zend Framework教程之Zend_Db_Table_Row用法實(shí)例分析
- Zend Framework教程之Zend_Db_Table用法詳解
- Zend Framework入門知識(shí)點(diǎn)小結(jié)
- Zend Framework緩存Cache用法簡(jiǎn)單實(shí)例
- Zend Framework基本頁(yè)面布局分析
- Zend Framework教程之配置文件application.ini解析
- Zend Framework教程之Loader以及PluginLoader用法詳解
- Zend Framework教程之連接數(shù)據(jù)庫(kù)并執(zhí)行增刪查的方法(附demo源碼下載)
相關(guān)文章
CodeIgniter中實(shí)現(xiàn)泛域名解析
這篇文章主要介紹了CodeIgniter中實(shí)現(xiàn)泛域名解析的方法,需要的朋友可以參考下2014-07-07
php同時(shí)使用session和cookie來(lái)保存用戶登錄信息的實(shí)現(xiàn)代碼
下面小編就為大家?guī)?lái)一篇php同時(shí)使用session和cookie來(lái)保存用戶登錄信息的實(shí)現(xiàn)代碼。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考,一起跟隨小編過(guò)來(lái)看看吧2016-05-05
wampserver改變默認(rèn)網(wǎng)站目錄的辦法
大家在做php項(xiàng)目時(shí),很多項(xiàng)目都會(huì)用到wampserver。WampServe集成了Apache、MySQL、PHP、phpmyadmin,支持Apache的mod_rewrite,PHP擴(kuò)展、Apache模塊只需要在菜單“開啟/關(guān)閉”上點(diǎn)點(diǎn)就搞定,省去了修改配置文件的麻煩,這里就簡(jiǎn)寫成wamp。2015-08-08
php使用CURL模擬GET與POST向微信接口提交及獲取數(shù)據(jù)的方法
這篇文章主要介紹了php使用CURL模擬GET與POST向微信接口提交及獲取數(shù)據(jù)的方法,結(jié)合實(shí)例形式分析了php使用curl向微信接口提交與獲取相關(guān)數(shù)據(jù)的操作技巧,需要的朋友可以參考下2016-09-09
PHP實(shí)現(xiàn)的帶超時(shí)功能get_headers函數(shù)
這篇文章主要介紹了PHP實(shí)現(xiàn)的帶超時(shí)功能的get_headers函數(shù),本文直接給出實(shí)現(xiàn)代碼,需要的朋友可以參考下2015-02-02
Laravel框架模型的創(chuàng)建及模型對(duì)數(shù)據(jù)操作示例
這篇文章主要介紹了Laravel框架模型的創(chuàng)建及模型對(duì)數(shù)據(jù)操作,結(jié)合實(shí)例形式分析了Laravel框架創(chuàng)建模型及使用模型進(jìn)行數(shù)據(jù)的增刪改查等相關(guān)操作技巧,需要的朋友可以參考下2019-05-05
php基于Redis消息隊(duì)列實(shí)現(xiàn)的消息推送的方法
這篇文章主要介紹了php基于Redis消息隊(duì)列實(shí)現(xiàn)的消息推送的方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-11-11

