PHP Reslter 3 通配符和自定义路由


PHP Reslter 3 Wildcard and Custom Routing

我在 Restler 上有这段代码,它返回 404 未找到

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

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

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

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

通配符路由尚不支持动态部分! 因此,您可以改为执行以下操作

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);
    }
}