2017-09-30 7 views
0

ZF3を使用してURLからパラメータを取得しようとして問題が発生しました。私はURLから任意の値を渡すしようとすると、私は常にデフォルト値を持っている:http://domain/game/1ZF3:URLからパラメータを受信しない

module.config.php

'game' => [ 
     'type' => Segment::class, 
     'options' => [ 
      'route' => '/game[/:id]', 
      'constraints' => [  
       'id' => '[0-9]*', 
      ],      
      'defaults' => [ 
       'controller' => Controller\GameController::class, 
       'action'  => 'index', 
      ], 
     ], 
    ], 

GameController.php

私は何
class GameController extends BaseController 
{ 

    public function indexAction() 
    { 
     $log = new LogWriter(); 

     $id = $this->params()->fromQuery('id', 'null'); 
     $log->writeLog(get_class($this) . "::" . __FUNCTION__ . " id partido: " . $id); 

     return []; 
    } 

} 

間違っている?

答えて

3

IDを取得するのにfromQuery()を使用していますが、IDはクエリ文字列に含まれていないため、ルートの一部です。あなたが代わりに欲しいのです:

$id = $this->params()->fromRoute('id', 'null'); 
+0

はそんなにティム・ファウンテンをありがとう!できます!!! –

関連する問題