gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-31 22:14:20 25 4
gpt4 key购买 nike

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com