2
0

Zend_Controller-ActionHelpers-ActionStack.xml 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <sect3 id="zend.controller.actionhelpers.actionstack">
  2. <title>动作堆栈(助手)</title>
  3. <para>
  4. <code>动作堆栈</code>助手允许把请求压到<link linkend="zend.controller.plugins.standard.actionstack">动作堆栈</link>前端控制器插件,有效地帮助你在请求期间创建一个动作队列来执行。(动作堆栈)助手允许你通过指定新的请求对象或通过“动作/控制器/模块”集合来添加动作。
  5. </para>
  6. <note>
  7. <title>调用动作堆栈助手来初始化动作堆栈插件</title>
  8. <para>
  9. 调用<code>动作堆栈</code> 助手暗中注册<code>动作堆栈</code> 插件 -- 这就意味着你不需要显性地注册<code>动作堆栈</code> 插件来用这个功能。
  10. </para>
  11. </note>
  12. <example id="zend.controller.actionhelpers.actionstack.simple">
  13. <title>用动作、控制器和模块名来添加一个任务</title>
  14. <para>
  15. 经常地,仅仅指定动作、控制器和模块(和可选的参数)最简单,和调用<code>Zend_Controller_Action::_forward()</code>一样:
  16. </para>
  17. <programlisting role="php"><![CDATA[
  18. class FooController extends Zend_Controller_Action
  19. {
  20. public function barAction()
  21. {
  22. // Add two actions to the stack
  23. // Add call to /foo/baz/bar/baz
  24. // (FooController::bazAction() with request var bar == baz)
  25. $this->_helper->actionStack('baz',
  26. 'foo',
  27. 'default',
  28. array('bar' => 'baz'));
  29. // Add call to /bar/bat
  30. // (BarController::batAction())
  31. $this->_helper->actionStack('bat', 'bar');
  32. }
  33. }
  34. ]]>
  35. </programlisting>
  36. </example>
  37. <example id="zend.controller.actionhelpers.actionstack.simple2">
  38. <title>使用请求对象添加一个任务</title>
  39. <para>
  40. 有时候请求对象的OOP本性很有用;你也可以传递这样一个对象给<code>动作堆栈</code>助手。
  41. </para>
  42. <programlisting role="php"><![CDATA[
  43. class FooController extends Zend_Controller_Action
  44. {
  45. public function barAction()
  46. {
  47. // Add two actions to the stack
  48. // Add call to /foo/baz/bar/baz
  49. // (FooController::bazAction() with request var bar == baz)
  50. $request = clone $this->getRequest();
  51. // Don't set controller or module; use current values
  52. $request->setActionName('baz')
  53. ->setParams(array('bar' => 'baz'));
  54. $this->_helper->actionStack($request);
  55. // Add call to /bar/bat
  56. // (BarController::batAction())
  57. $request = clone $this->getRequest();
  58. // don't set module; use current value
  59. $request->setActionName('bat')
  60. ->setControllerName('bar');
  61. $this->_helper->actionStack($request);
  62. }
  63. }
  64. ]]>
  65. </programlisting>
  66. </example>
  67. </sect3>
  68. <!--
  69. vim:se ts=4 sw=4 et:
  70. -->