2013-07-25 85 views
1

我喜歡URLS:ZF2如何通過URL段爲行動PARAMS

http://www.example.com/r/4442323222344/HLKKLKLKLKLKLKH

我想對URL的兩段(4442323222344和HLKKLKLKLKLKLKH)映射爲則params的我redirectAction功能,所以$ MESSAGEID是 「」 和$哈希是「HLKKLKLKLKLKLKH

這是路線:

'router' => array(
     'routes' => array(
      .... 
      'redirect' => array(
       'type' => 'Literal', 
       'options' => array(
        'route' => '/r', 
        'defaults' => array(
         '__NAMESPACE__' => 'Application\Controller', 
         'controller' => 'Application\Controller\Index', 
         'action'  => 'redirect', 
        ), 
       ), 
       'may_terminate' => true, 
       'child_routes' => array(
        'default' => array(
         'type' => 'Segment', 
         'options' => array(
          'route' => '/:messageId/:hash', 
          'constraints' => array(
           'messageId' => '[a-zA-Z0-9]+', 
           'hash'  => '[a-zA-Z0-9]+', 
          ), 
          'defaults' => array(
          ), 
         ), 
        ), 
       ), 
      ), 
      ... 
     ), 
    ), 

這就是今天的行動:

class IndexController extends AbstractActionController implements ConfigAwareInterface 
{ 
    ... 
    public function redirectAction($messageId,$hash) 
    { 
     ... 
     myFunc($messageId,$hash); 
     ... 
    } 
    ... 
} 

我知道,我可以使用有這些部分:

$_messageId = $this->params()->fromRoute('messageId'); 
$_hash = $this->params()->fromRoute('hash'); 

,但我通過函數params發現pass變量更加「乾淨」。

回答

1

這是目前不可能做到這一點。這是ZF3的一個改進(它不會很快發佈,所以不用擔心),但是在ZF2中你不會看到這個功能的發佈。

你需要去使用params() -plugin現在

+0

這真是出乎意料,但我可以生存:) –