我体验过Zend Framework 1,并使用该框架构建了一些应用程序。
现在,我正在试验Zend Framework 2,但我被url参数卡住了。我已经这样设置了我的路由:
// Setup for router and routes
'Zend'Mvc'Router'RouteStack' => array(
'parameters' => array(
'routes' => array(
'default' => array(
'type' => 'Zend'Mvc'Router'Http'Segment',
'options' => array(
'route' => '/[:slug]',
'constraints' => array(
'slug' => '[a-zA-Z][a-zA-Z0-9_'/-]*'
),
'defaults' => array(
'controller' => 'Htmlsite'Controller'BootController',
'action' => 'index',
'slug' => 'home'
),
),
),
'home' => array(
'type' => 'Zend'Mvc'Router'Http'Literal',
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'Htmlsite'Controller'BootController',
'action' => 'index',
),
),
),
),
),
),
正如你所看到的,我试着制作一个可变的鼻涕虫。如何访问此变量?
或者简单地说:
$slug= $this->params('slug');
为什么不选择这个:
$this->params()->fromRoute('slug');
从这里开始:
$slug = $this->getEvent()->getRouteMatch()->getParam('slug');
这里有更多的文档,但看起来有点不完整。
您也可以简单地使用
$this->params()->fromQuery('slug',null);
$this->params()->fromPost('slug',null);
我希望它能起作用。。。