php - 在 reSTLer 中使用驼峰式大小写作为函数名

标签 php restler

This is the web service file _ws.php
<?php
/*
 Title: Hello World Example.
 Tagline: Let's say hello!.
 Description: Basic hello world example to get started with Restler 2.0.
 Example 1: GET say/hello returns "Hello world!".
 Example 2: GET say/hello/restler2.0 returns "Hello Restler2.0!".
 Example 3: GET say/hello?to=R.Arul%20Kumaran returns "Hello R.Arul Kumaran!".
 */
require_once '../restler/restler.php';
require_once 'news_class.php';
$r = new Restler();
$r->addAPIClass('news');
$r->handle();

这是具有以下功能的类文件:

<?php
class news {
    function hello($to='world') {
        return "Hello $to!";
    }

    function listnews($page=0){
        $result = "";

        $xml_doc = new DOMDocument;
        $xml_doc->load('news.xml');

        $xsl_doc = new DOMDocument;
        $xsl_doc->load('news_list.xsl');

        $xsl_proc = new XSLTProcessor();
        $xsl_proc->importStyleSheet($xsl_doc);
        $xsl_proc->setParameter('', 'page', $page);
        $result = $xsl_proc->transformToXml($xml_doc);

        return $result;
    }


} // news -

如果我将 listnews 函数命名为 listNews,我会得到这个错误:

{
  "error": {
    "code": 404,
    "message": "Not Found"
  }
}

只要名称现在是大小写混合的,它就可以工作。 它应该是这样的吗?有没有办法使用 Camel 套管?

谢谢!

最佳答案

只是为了重新审视这一点,我一直在研究代码并且我得到了类似的行为。我的方法的以下命名约定会导致 404 错误:

mysite.com/myclass/testMethod
mysite.com/myclass/TestMethod

下面的工作符合预期

mysite.com/myclass/testmethod
mysite.com/myclass/test_method

有什么方法(我错过或以其他方式)让 Camel Case 工作?

更新:方法名称似乎不是导致错误的原因,例如我可以将其命名为 testMethod,并且仍然以小写形式调用它。

关于php - 在 reSTLer 中使用驼峰式大小写作为函数名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8479764/

相关文章:

node.js - 如何使用 ReSTLer 下载网站并将其写入文件?

php - 所有 Url 的 ReSTLer 都出现 404 错误

PHP:重用对象或复制到数组中更快吗

php - 如何获取wordpress帖子的描述和标题?

PHPExcel 根据单元格值设置字体/背景颜色

PHP AJAX MySQL 表单中的插入日期输入为 : 12/31/1969

javascript - node.js reSTLer 调用的多个响应

php - ReSTLer:作为参数的复杂对象类型

javascript - 如何使用 AJAX 和 JSON 获取 PHP 文件返回的数据