我的网址如下:
我想将网址的两个网段(4442323222344和HLKKLKLKLKLKLKH)映射为 redirectAction 功能的参数,因此 $ messageId 为“ 4442323222344 “和 $ hash 是” 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');
但我发现通过函数参数传递变量更加“干净”。