2014-02-18 3 views
0

zend2 프로젝트를 시작했으며 라우팅 시스템을 파악할 수 없습니다. 뷰에서 컨트롤러로 일부 변수를 전달하는 데 정말로 도움이 필요합니다. 내가 매개 변수를 전달하려는 어디 방법 내 컨트롤러 2 가지 방법이zend framework 2 라우팅 구성 및 매개 변수 전달

<?php 
return array(
'controllers' => array(
    'invokables' => array(
     'Map\Controller\Index' => 'Map\Controller\IndexController', 
    ), 
), 
'router' => array(
    'routes' => array(
     'map' => array(
      'type' => 'segment', 
      'options' => array(
       // Change this to something specific to your module 
       'route' => '/map[/:action][/:tileId]', 
       'defaults' => array(
        // Change this value to reflect the namespace in which 
        // the controllers for your module are found 
        '__NAMESPACE__' => 'Map\Controller', 
        'controller' => 'Index', 
        'action'  => 'index', 
       ), 
      ), 
      'may_terminate' => true, 
      'child_routes' => array(
       // This route is a sane default when developing a module; 
       // as you solidify the routes for your module, however, 
       // you may want to remove it and replace it with more 
       // specific routes. 
       'default' => array(
        'type' => 'Segment', 
        'options' => array(
         'route' => '/[:controller[/:action]]', 
         'constraints' => array(
          'controller' => '[a-zA-Z][a-zA-Z0-9_-]*', 
          'action'  => '[a-zA-Z][a-zA-Z0-9_-]*', 
         ), 
         'defaults' => array(
         ), 
        ), 
       ), 
      ), 
     ), 
    ), 
), 
'view_manager' => array(
    'template_path_stack' => array(
     'map' => __DIR__ . '/../view', 
    ), 
), 
); 

: 그것은 다음과 같이 모듈 구성 보이는

public function buyTileAction($tileId){ 
    echo $tileId; 
} 

와 유사 하나, 문제는 "나는 시도이다 myappname.dev/map/buy-tile "메소드를 입력하고 예를 들어 문자열 만 출력하지만"myappname.dev/map/buy-tile/tileId/1 "와 같은 매개 변수를 전달하려고하면 ' 컨트롤러의 값을 수신하지 마십시오.

고맙습니다.

답변

0

시도 :

$tileId = $this->getEvent()->getRouteMatch()->getParam('tileId'); 
+0

안녕하세요, 두 솔루션을 시도 (@ 아담 H의와 KeyneON의이 @), 아무도 나에게 예상되는 결과를 제공하지 않습니다. 변수 값을 인쇄하는 대신 요청에서 "요청한 URL을 라우팅으로 일치시킬 수 없습니다."라고 표시합니다. myappname.dev/map/buy-tile/tileId/1에 액세스하려고하면 누구든지이 문제를 해결하는 방법에 대해 다른 생각을 갖고 있습니까? 고맙습니다. – Susy11

2

이 작업은 수행해야 할 작업입니다.

public function buyTileAction() { 
    $tileId = $this->params()->fromRoute('tileId'); 
}