2010-03-31 2 views
9

젠드 프레임 워크에서 매개 변수 ($ _POST 또는 $ _GET)를 리디렉션 헬퍼와 함께 전달할 수 있습니까? 다음 코드는 현재 컨트롤러의 동작을 인덱스로 리디렉션하지만 일부 매개 변수도 전달하려고합니다.Zend Framework에서 리디렉터 도우미를 사용하여 매개 변수를 전달하는 방법은 무엇입니까?

$this->_helper->redirector("index"); 

젠드 Documenataion은 그것에 대해 아무 말도하지 않습니다.

답변

19

물론. 이것은 Action Helpers documentation의 코드 샘플입니다 (Redirector 섹션, 페이지 아래쪽 약 2/3 절 참조). 리디렉터 도우미에 대한 참조를 가져와이 코드가 수행하는 goto* 메서드 중 하나를 호출해야 할 수 있습니다.

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을! 어떻게 그럴 수 있겠 어! 정말 고마워! – Moon

+0

위에서 언급 한 Action Helpers 문서가 404 버전을 반환하는 대신 버전 1.12에서 시도해 봅니다 - https://framework.zend.com/manual/1.12/en/zend.controller.actionhelpers.html – PiggyMacPigPig

+0

Zend 3.0.0을 사용하고 내 매개 변수는 리다이렉터 (모듈, 액션, 컨트롤러, 매개 변수)입니다. –

8

4 매개 변수로 배열을 전달합니다 아 //

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

사용하는 "모듈"매개 변수는 무엇입니까? – softwareplay

+1

@softwareplay 사용중인 모듈의 이름, 모듈이 없으면 비워 두어야한다고 생각합니다. http://framework.zend.com/manual/2.0/en/user-guide/modules.html – Rahman

관련 문제