简体   繁体   English

Zend框架路由错误

[英]Zend framework routing error

I have a problem with a routing in Zend framework. 我在Zend框架中路由存在问题。

'name' => array(
    'type' => 'Zend\Mvc\Router\Http\Segment',
    'options' => array(
        'route'    => '/site/:id/orders[/:page]',
        'constraints' => array(
            'id' => '[0-9]*',
            'page'    => '[0-9]*'
        ),
        'defaults' => array(
            'controller' => 'Application\Controller\Site',
            'action'     => 'action'
        ),
    ),
),

And in a controller. 并在控制器中。

$id = (int) $this->params()->fromRoute('id');

And in some (!) cases a browser returns this error - "Missing parameter 'id'", but I don't know why. 在某些情况下,浏览器会返回此错误-“缺少参数'id'”,但我不知道为什么。

Can anybody help me on this issue? 有人可以帮我解决这个问题吗?

well based on your route configuration id must exist in your routes, so the link you requested didn't have id . 根据您的路由配置,好ID必须存在于您的路由中,因此您请求的链接没有id。 and your constrains also should change to 'id' => '[0-9]+' so the id must exist. 并且您的约束也应更改为'id'=>'[0-9] +',因此ID必须存在。

and also you get the id in the controller by just typing 而且您只需输入以下内容即可在控制器中获取ID

$id=$this->params("id");

which will get the id too 这也将获得ID

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM