<tfoot id='k9qRz'></tfoot>

      <bdo id='k9qRz'></bdo><ul id='k9qRz'></ul>
  • <i id='k9qRz'><tr id='k9qRz'><dt id='k9qRz'><q id='k9qRz'><span id='k9qRz'><b id='k9qRz'><form id='k9qRz'><ins id='k9qRz'></ins><ul id='k9qRz'></ul><sub id='k9qRz'></sub></form><legend id='k9qRz'></legend><bdo id='k9qRz'><pre id='k9qRz'><center id='k9qRz'></center></pre></bdo></b><th id='k9qRz'></th></span></q></dt></tr></i><div id='k9qRz'><tfoot id='k9qRz'></tfoot><dl id='k9qRz'><fieldset id='k9qRz'></fieldset></dl></div>
  • <small id='k9qRz'></small><noframes id='k9qRz'>

        <legend id='k9qRz'><style id='k9qRz'><dir id='k9qRz'><q id='k9qRz'></q></dir></style></legend>

      1. 如何设置分层 Zend 休息路线?

        时间:2023-10-02

            • <tfoot id='iYnvh'></tfoot>
              <i id='iYnvh'><tr id='iYnvh'><dt id='iYnvh'><q id='iYnvh'><span id='iYnvh'><b id='iYnvh'><form id='iYnvh'><ins id='iYnvh'></ins><ul id='iYnvh'></ul><sub id='iYnvh'></sub></form><legend id='iYnvh'></legend><bdo id='iYnvh'><pre id='iYnvh'><center id='iYnvh'></center></pre></bdo></b><th id='iYnvh'></th></span></q></dt></tr></i><div id='iYnvh'><tfoot id='iYnvh'></tfoot><dl id='iYnvh'><fieldset id='iYnvh'></fieldset></dl></div>
                <bdo id='iYnvh'></bdo><ul id='iYnvh'></ul>

                  <small id='iYnvh'></small><noframes id='iYnvh'>

                    <tbody id='iYnvh'></tbody>
                  <legend id='iYnvh'><style id='iYnvh'><dir id='iYnvh'><q id='iYnvh'></q></dir></style></legend>

                1. 本文介绍了如何设置分层 Zend 休息路线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  使用 Zend 框架,我尝试在按以下模式组织的资源上为 REST api 构建路由:

                  • http://example.org/users/
                  • http://example.org/users/234
                  • http://example.org/users/234/items
                  • http://example.org/users/234/items/34

                  我如何使用 Zend_Rest_Route 进行设置?

                  这是我在 bootstrap.php 文件中为用户资源 (users/:id) 设置路由的方法:

                   $this->bootstrap('frontController');$frontController = Zend_Controller_Front::getInstance();$restRoute = new Zend_Rest_Route($frontController);$frontController->getRouter()->addRoute('default', $restRoute);

                  [据我所知,这是一个包罗万象的路线,因此 users/324/items/34 将导致参数设置为 id=324 和 items=34,并且所有内容都将映射到用户(前端模块)模型.从那里我想我可以只测试 items 参数并在 get 请求中为用户 #324 检索项目 #34.]<=== 我刚刚检查了它,它似乎不是这样工作的:

                  访问/users/234/items/43 和

                  var_dump($this->_getAllParams());

                  在其余控制器的 get 操作中产生以下输出:

                  array(4) {[控制器"]=>字符串(5)用户"[动作"]=>字符串(3)获取"[2]=>string(5) "items" ["module"]=>字符串(7)默认"]}

                  不知何故,两个 ID 都丢失了...

                  有人吗?

                  解决方案

                  AFAIK,Zend_Rest_Route 中没有允许您执行此类操作的功能.有一个提案,但不确定何时实施.您可以将其添加到 Bootstrap 中以设置此自定义路由.

                  $front = $this->getResource('FrontController');$testRoute = new Zend_Controller_Router_Route('users/:user_id/items/:item_id',大批('控制器' =>'用户','动作' =>'物品','模块' =>'默认'));$front->getRouter()->addRoute('test', $testRoute);

                  user_iditem_id 在 UsersController 的 itemAction 中作为参数可用:

                  $user_id = $this->_request->getParam('user_id');

                  With the Zend Framework, I am trying to build routes for a REST api on resources organized in the following pattern:

                  • http://example.org/users/
                  • http://example.org/users/234
                  • http://example.org/users/234/items
                  • http://example.org/users/234/items/34

                  How do I set up this with Zend_Rest_Route?

                  Here is how I have setup the route for the users resource (users/:id) in my bootstrap.php file:

                    $this->bootstrap('frontController');
                    $frontController = Zend_Controller_Front::getInstance();
                    $restRoute = new Zend_Rest_Route($frontController);
                    $frontController->getRouter()->addRoute('default', $restRoute);
                  

                  [As far as I understand, this is a catch all route so users/324/items/34 would results in parameters set as id=324 and items=34 and everything would be mapped to the Users (front module) Model. From there I guess I could just test for the items parameter and retrieve the item #34 for user #324 on a get request.]<=== I just checked it and it doesn't seems to work like that:

                  Acessing /users/234/items/43 and

                  var_dump($this->_getAllParams());
                  

                  in the get action of the rest controller results in the following output:

                  array(4) {
                   ["controller"]=> string(5) "users"
                   ["action"]=>  string(3) "get"
                   [2]=>  string(5) "items"  ["module"]=>  string(7) "default"]
                  }
                  

                  Somehow both ids got lost...

                  Anyone?

                  解决方案

                  AFAIK, there is no feature in Zend_Rest_Route which allows you to do something like this. There is a proposal but not sure when it'll be implemented. You can add this in your Bootstrap to set up this custom route.

                  $front = $this->getResource('FrontController'); 
                  $testRoute = new Zend_Controller_Router_Route(
                      'users/:user_id/items/:item_id',
                      array(
                          'controller' => 'users',
                          'action' => 'item',
                          'module' => 'default'
                      )
                  );
                  
                  $front->getRouter()->addRoute('test', $testRoute);
                  

                  user_id or item_id become available in itemAction in UsersController as parameters:

                  $user_id = $this->_request->getParam('user_id');
                  

                  这篇关于如何设置分层 Zend 休息路线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:PHP 会话修改缓存控制标头? 下一篇:Zend 框架,$this->_forward 在做什么

                  相关文章

                  最新文章

                  • <bdo id='X93sY'></bdo><ul id='X93sY'></ul>
                2. <tfoot id='X93sY'></tfoot>

                  1. <small id='X93sY'></small><noframes id='X93sY'>

                    <i id='X93sY'><tr id='X93sY'><dt id='X93sY'><q id='X93sY'><span id='X93sY'><b id='X93sY'><form id='X93sY'><ins id='X93sY'></ins><ul id='X93sY'></ul><sub id='X93sY'></sub></form><legend id='X93sY'></legend><bdo id='X93sY'><pre id='X93sY'><center id='X93sY'></center></pre></bdo></b><th id='X93sY'></th></span></q></dt></tr></i><div id='X93sY'><tfoot id='X93sY'></tfoot><dl id='X93sY'><fieldset id='X93sY'></fieldset></dl></div>

                      <legend id='X93sY'><style id='X93sY'><dir id='X93sY'><q id='X93sY'></q></dir></style></legend>