3
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"
  }
}

只要名称现在混合大小写,它就可以工作。是不是应该是这样的?有没有办法使用骆驼肠衣?

谢谢!

4

2 回答 2

0

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

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

以下工作按预期进行

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

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

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

于 2012-03-26T09:54:04.143 回答
0

更新@richard_askew 的答案,他是对的。

当我们在 Restler 2.1.5 或更低版本中使用自动路由时,类名、方法名和参数名在 URL 中必须全部小写

我们刚刚发布了Restler 2.1.6 版,它改变了这种行为 :)

现在类名、方法名和url中指定的参数名在任何情况下(大写或小写或混合)都会与正确的方法匹配

于 2012-05-15T01:05:28.533 回答