这是路线。。。
'panel-list' => array (
'type' => 'Segment',
'options' => array (
'route' => '/panel-list/:pageId[/:action]',
'constraints' => array (
'pageId' => '[a-z0-9_-]+'
),
'defaults' => array (
'action' => 'index',
'controller' => 'PanelList',
'site' => null
),
),
),
我需要在这里放些什么。。。。
public function indexAction()
{
echo ???????
}
以回显pageId?
在zf2的beta5中,它变得更容易使用,因此您不需要记住每个不同类型的不同语法。我引用:
新的"Params"控制器插件。允许检索查询、发布、,cookie、标头和路由参数。用法为$this->params()->fromQuery($name,$default)。
因此,要从路线中获得一个参数,你所需要做的就是。
$param = $this->params()->fromRoute('pageId');
正如引文所说,这也可以通过查询($_GET)和发布($_post)等来完成。
$param = $this->params()->fromQuery('pageId');
// will match someurl?pageId=33
$param = $this->params()->fromPost('pageId');
// will match something with the name pageId from a form.
// You can also set a default value, if it's empty.
$param = $this->params()->fromRoute('key', 'defaultvalue');
示例:
$param = $this->params()->fromQuery('pageId', 55);
如果url是someurl?pageId=33$param将保存值33。如果url没有?pageId$param将保存值55
你试过吗
$this->getRequest()->getParam('pageId')
$this->getEvent()->getRouteMatch()->getParam('pageId');