搜尋
首頁php教程PHP源码zend历程 之 初认控制器

<script>ec(2);</script>
从入门PHP的第二个星期,就开是接触Zend framework了,可是,后来就放了。当时没有做下笔记,接着就什么都忘了,回悔啊,现在重新学过吧!
今天要看的是控制器,这玩意太大,我也只是看看皮毛,由浅入深吧!
下面是一个简单的控制器:

 class helloController extends Zend_Controller_Action
{
    function indexAction()
    {
        echo "hi, this is my helloworld";
    }

    function testAction()
    {
        $var1 = $this->_getParam("var");
        echo "hello".$book_id;
    }

  

    function __call($action,$args){
        $this->_redirect(''/hello'');
    }
}

运行结果是这样的:

http://localhost/hello/test/var/world 会显示 hellowrold

http://localhost/hello/netaction 时,会显示 hi, this is my helloworld

 

其实我想说明的也就上面分色的两点:

:在Zend中,我有接收参数,不管是 post 还是 get 的,只要用 如:

$this->_getParam("var");

的形式即可,

final protected function _getParam($paramName, $default = null) 是控制器的私有方法,它还要可是带第二个参数,作为默认值,当没有得到你想要的参数时,返回这个默认值。

 

:这个函数的目的为是,当访问的方法不存在时,自己转到一个地址(这里就是:http://localhost/hello 了)

 

陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

Atom編輯器mac版下載

Atom編輯器mac版下載

最受歡迎的的開源編輯器

EditPlus 中文破解版

EditPlus 中文破解版

體積小,語法高亮,不支援程式碼提示功能

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

將Eclipse與SAP NetWeaver應用伺服器整合。