【问题标题】:PHP Reslter 3 Wildcard and Custom RoutingPHP Reslter 3 通配符和自定义路由
【发布时间】:2015-01-09 00:31:49
【问题描述】:

我在 Restler 上有这段代码,它返回 404 Not Found

class CRUDEntity {
  /**
   * @url GET /entity/{entity_id}/books/*
   */    
  function getBatch($entity_id) {
    var_dump(func_get_args());
  }
}

在索引页面上我有以下内容:

$r->addAPIClass('CRUDEntity','');

这个想法是进入 url /entity/1/books/10/12/13/14 但它返回 404 错误。你知道我该怎么做吗?

【问题讨论】:

    标签: php wildcard restler


    【解决方案1】:

    通配符路由还不支持动态部分!所以您可以改为执行以下操作

    class CRUDEntity
    {
        /**
         * @param int $entity_id
         *
         * @url GET /entity/*
         */
        function getBatch($entity_id, $books = 'books')
        {
            if (!is_numeric($entity_id) || $books != 'books') {
                throw new RestException(404);
            }
            $dynamicArguments = func_get_args();
            array_shift($dynamicArguments);
            array_shift($dynamicArguments);
            var_dump($dynamicArguments);
        }
    }
    

    【讨论】:

    • 谢谢,我使用与您提到的类似的方法解决了这个问题。很高兴看到这种有很多选择的框架。
    猜你喜欢
    • 1970-01-01
    • 2014-03-07
    • 2013-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-10
    相关资源
    最近更新 更多