我的网址如下:
我想将 URL 的两个部分(4442323222344 和 HLKKLKLKLKLKLKLKH)映射为我的redirectAction函数的参数,所以$messageId是“ 4442323222344 ”和$hash是“ HLKKLKLKLKLKLKLKH ”
这是路线:
'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');
但我发现通过函数参数传递变量更“干净”。