I'm twiting

访问统计

free counters

转一贴,内容不难,却具启发性:zend历程 之 初认控制器

原文地址

一个简单的控制器:

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 了)

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>