Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Zend framework2 Zend Framework 2 url帮助程序_Zend Framework2 - Fatal编程技术网

Zend framework2 Zend Framework 2 url帮助程序

Zend framework2 Zend Framework 2 url帮助程序,zend-framework2,Zend Framework2,我想知道为什么没有显示id参数。生成的URL为:“”,但我预期为“”。我错过了什么 控制器代码: echo "<a href='" . $this->url('home', array('action' => 'editroom', 'id' => $room->getId())) . "' title='Bearbeiten des Eintrags'>Bearbeiten</a>;"; echo“; 您可能没有在起始路线中定义id参数。您需要

我想知道为什么没有显示id参数。生成的URL为:“”,但我预期为“”。我错过了什么

控制器代码:

echo "<a href='" . $this->url('home', array('action' => 'editroom', 'id' => $room->getId())) . "' title='Bearbeiten des Eintrags'>Bearbeiten</a>;";
echo“;

您可能没有在起始路线中定义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>;";
echo“;

@sroes感谢您的建议。我混合了路由的名称,路由的名称是editroom而不是home-:-)正如我已经提到的,我混合了路由的名称。感谢您的帮助@sroes!