我想知道为什么没有显示id参数。生成的网址为:“http://example.org/editroom”但我希望“http://example.org/editroom/2”。我错过了什么?
控制器的代码:
echo "<a href='" . $this->url('home', array('action' => 'editroom', 'id' => $room->getId())) . "' title='Bearbeiten des Eintrags'>Bearbeiten</a>;";
答案 0 :(得分:1)
您可能没有在归属路由中定义id参数。您需要添加子路由以允许其他参数:
'home' => array(
'type' => 'Zend\Mvc\Router\Http\Segment',
'options' => array(
'route' => '/[:controller[/[:action]]]',
'constraints' => array(
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
'controller' => 'Application\Controller\IndexController',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'wildcard' => array(
'type' => 'Zend\Mvc\Router\Http\Wildcard',
'options' => array(
'key_value_delimiter' => '/',
'param_delimiter' => '/',
),
),
),
)
然后你这样称呼它:
echo "<a href='" . $this->url('home/wildcard', array('action' => 'editroom', 'id' => $room->getId())) . "' title='Bearbeiten des Eintrags'>Bearbeiten</a>;";