本文講述了Zend Framework教程之MVC框架的Controller用法。分享給大家供大家參考,具體如下:
這里簡單講講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目錄下。
可以通過以下方式自定義路徑:
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');
默認(rèn)情況下存放在默認(rèn)的目錄即可。
2.文件名和類名相同
3.類名以Controller結(jié)尾,并且繼承Zend_Controller_Action
4.類名第一個字母大寫,遵守駝峰風(fēng)格。利潤NewsListControlle
4.文件名以Controller.php結(jié)尾
5.Controller的初始化工作可以在init方法中完成
public function init() { }
? ?
希望本文所述對大家PHP程序設(shè)計(jì)有所幫助。
更多Zend Framework教程之MVC框架的Controller用法分析相關(guān)文章請關(guān)注PHP中文網(wǎng)!

ホットAIツール

Undress AI Tool
脫衣畫像を無料で

Undresser.AI Undress
リアルなヌード寫真を作成する AI 搭載アプリ

AI Clothes Remover
寫真から衣服を削除するオンライン AI ツール。

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

メモ帳++7.3.1
使いやすく無料のコードエディター

SublimeText3 中國語版
中國語版、とても使いやすい

ゼンドスタジオ 13.0.1
強(qiáng)力な PHP 統(tǒng)合開発環(huán)境

ドリームウィーバー CS6
ビジュアル Web 開発ツール

SublimeText3 Mac版
神レベルのコード編集ソフト(SublimeText3)

ホットトピック









