1
我喜歡URLS:ZF2如何通過URL段爲行動PARAMS
我想對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變量更加「乾淨」。
這真是出乎意料,但我可以生存:) –