次のような URL を取得しました。
URL の 2 つのセグメント (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');
しかし、関数パラメーターを介して変数を渡す方が「クリーン」であることがわかりました。