一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

zend历程 之 初认控制器

时间:2008-04-24 编辑:简简单单 来源:一聚教程网

从入门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 了)