2014-04-22 7 views
0

저는 zf2에서 새롭고 URL에서 매개 변수를 가져오고 싶습니다. 하지만 쓸 때zf2에서 url로부터 매개 변수를 얻는 방법은 무엇입니까?

if($this->getRequest()->isGet()) { 
       $get = $this->params()->fromQuery(); 
      } 
      print_r($get); 

컨트롤러에서 빈 배열을 반환합니다. URL에서 매개 변수를 가져 오는 방법은 무엇입니까?

내가 46을 얻으려면

http://test.zeptosystems.com/event/create/46/1396465200/1

가 어떻게이 매개 변수를 얻을 수 있습니다 : 여기 내 URL은?

답변

3

컨트롤러에서 당신이 할 수있는에 Params의 플러그인 : 일부 ?var=value&var2=somevalue에서 GET PARAMS 표준

$this->params()->fromQuery(); 

그러나 fromQuery 돌아갑니다. 당신이 좋은 URL을 가지고 있기 때문에 당신이

$this->params()->fromRoute(); 

은 자세한 내용

에 대한 Reference of Params class 또는 ZF2 Manual Controller's plugins page를 참조 사용해야
-3
use Symfony\Component\HttpFoundation\Request; 
use Symfony\Component\HttpFoundation\Response; 


class FooController extends Controller 
{ 

// stuff 

    public function showAction(){ 

     // and to show http req 
     $req = new Request(); 
     $foo = $req->get('foo'); 

     return new Response('Get Parameter -> '.$foo); 

    } 
} 
+2

ZF2 프로젝트 심포니의 클래스? 정말? 왜? ;-) –