Zend Framework: Action Helper

Zend Framework 默认包含了许多action helper:

  • AutoComplete用来自动response AJAX autocompletion;
  • ContextSwitchAjaxContext服务于你的actions的交替response格式;
  • FlashMessenger用来处理session flash messages;
  • Json用来encoding和发送JSON response;
  • Redirector提供不同的实现方法来重定向到你的应用中的不同的页面(这里也就是说$this->redirect());
  • ViewRenderer用来自动化设置view object给你的controller和rendering views。

ActionStack

*ActionStack*helper允许你push requests给ActionStack front controller plugin,非常有效的帮助你在执行request时创建一个actions队列。这个helper允许你通过指定一个新的request或action-controller-module set的方式添加actions。

My comprehension

也就是说这个ActionStack可以用来控制action的访问的,也就是在controller里面的Action方法中让它也能用上其他action里面的功能,在功能都一样的情况下,就没必要多写一遍,使用这个方法就可以很好来在action里请求别的action。下面上代码(Zend文档里面的)
Example#1Adding a Task Using Action, Controller and Module Names
这就和Zend_Controller_Action::_forward()是一样的

class FooController extends Zend_Controller_Action
{
    public function barAction()
    {
        // Add two actions to the stack
        // Add call to /foo/baz/bar/baz
        // (FooController::bazAction() with request var bar == baz)
        $this->_helper->actionStack('baz',
                                    'foo',
                                    'default',
                                    array('bar' => 'baz'));

        // Add call to /bar/bat
        // (BarController::batAction())
        $this->_helper->actionStack('bat', 'bar');
    }
}

Example #2 Adding a Task Using a Request Object
有时候OOP特性中的request object非常有意义;你也可以通过object的方法发送给ActionStack

class FooController extends Zend_Controller_Action
{
    public function barAction()
    {
        // Add two actions to the stack
        // Add call to /foo/baz/bar/baz
        // (FooController::bazAction() with request var bar == baz)
        $request = clone $this->getRequest();
        // Don't set controller or module; use current values
        $request->setActionName('baz')
                ->setParams(array('bar' => 'baz'));
        $this->_helper->actionStack($request);

        // Add call to /bar/bat
        // (BarController::batAction())
        $request = clone $this->getRequest();
        // don't set module; use current value
        $request->setActionName('bat')
                ->setControllerName('bar');
        $this->_helper->actionStack($request);
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值