我正在使用Restler 2.0,我正在尝试添加一个基于CRUD示例的新路由
$o['GET']['author/:name/:email']=array (
'class_name' => 'Author',
'method_name' => 'getLogin',
'arguments' =>
array (
'name' => 0,
'email' => 1,
),
'defaults' =>
array (
0 => NULL,
1 => NULL,
),
'metadata' =>
array (
),
'method_flag' => 0,
);
当我在浏览器中调用url时,http://[host]/author/[name to pull]/[email to pull]
我得到以下错误:
<>之前{"错误":{"代码":404年,"message": "Not Found"}}之前我的作者代码已更新为以下方法
function getLogin($name=NULL,$email=NULL) {
print "in author, getting login";
return $this->dp->getLogin($name,$email);
}
Luracast Restler自动路由
首先,routes.php
是在生产模式下运行Restler时自动生成的
$r = new Restler(TRUE);
在调用
时会被覆盖$r->refreshCache();
或者在调试模式下运行,所以它不应该手工编码。
Restler 2.0使用自动映射,在更新的CRUD示例中有更好的解释。
方法的更正版本应该是
function get($name=NULL,$email=NULL) {
print "in author, getting login";
return $this->dp->getLogin($name,$email);
}
将映射到
GET /author/:email/:password
如果你的方法当前映射到
GET /author/login/:email/:password
Luracast Restler自定义路由
还请注意,您可以使用PHPDoc注释来创建自定义映射,并且可以添加多个映射。例如
/*
* @url GET /custom/mapping/:name/:email
* @url GET /another/:name/:email
*/
function get($name=NULL,$email=NULL) {
print "in author, getting login";
return $this->dp->getLogin($name,$email);
}
这将创建以下路由,并禁用该方法的自动路由。
GET /author/custom/mapping/:email/:password
GET /author/another/:email/:password