2010-03-31 27 views

Trả lời

19

Tất nhiên. Đây là một mẫu mã từ Action Helpers documentation (xem phần Redirector, khoảng 2/3 đường xuống trang.) Bạn có thể cần lấy một tham chiếu đến trình trợ giúp redirector và gọi một trong các phương thức goto* như mã này đang làm.

class ForwardController extends Zend_Controller_Action 
{ 
    /** 
    * Redirector - defined for code completion 
    * 
    * @var Zend_Controller_Action_Helper_Redirector 
    */ 
    protected $_redirector = null; 

    public function init() 
    { 
     $this->_redirector = $this->_helper->getHelper('Redirector'); 
    } 

    public function myAction() 
    { 
     /* do some stuff */ 

     // Redirect to 'my-action' of 'my-controller' in the current 
     // module, using the params param1 => test and param2 => test2 
     $this->_redirector->gotoSimple('my-action', 
             'my-controller', 
             null, 
             array('param1' => 'test', 'param2' => 'test2')); 
    } 
} 
+0

@Andy Shellam // ah! Làm thế nào tôi có thể bỏ lỡ điều đó! Cảm ơn bạn rất nhiều! – Moon

+0

Tài liệu về Trình trợ giúp hành động được tham chiếu ở trên là trả lại 404 dùng thử thay cho phiên bản 1.12 - https://framework.zend.com/manual/1.12/en/zend.controller.actionhelpers.html – PiggyMacPigPig

+0

Tôi sử dụng Zend 3.0.0 và thứ tự param của tôi là redirector (module, action, controller, params) –

8

Vượt qua một mảng như tham số thứ 4:

$this->_helper->redirector('action', 'controller', 'module', array('param1' => 'value1')); 
+0

tham số "module" mà bạn sử dụng là gì? – softwareplay

+1

@softwareplay Tên của mô-đun bạn đang sử dụng, nếu không có mô-đun, tôi nghĩ bạn nên đặt trống. http://framework.zend.com/manual/2.0/en/user-guide/modules.html – Rahman

Các vấn đề liên quan