Tonic.PHP 关于具有“/resource”和“/resource/id”URL 的
Posted
技术标签:
【中文标题】Tonic.PHP 关于具有“/resource”和“/resource/id”URL 的【英文标题】:Tonic.PHP on having "/resource" and "/resource/id" URL's 【发布时间】:2014-03-24 02:23:42 【问题描述】:我正在尝试获取 URL“/videoGame”来运行“listAllVideoGames”方法和“/videoGame/#”(其中# 是一个数字)来运行“getVideoGame”方法。使用“@priority”注释更改优先级我可以同时调用两个 URL,但找不到执行我描述的方法。
/**
* @uri /videoGame
* @uri /videoGame/:id
*/
class VideoGame extends Resource
protected function getDao()
return new VideoGameDao();
/**
* @uri /videoGame
* @json
* @provides application/json
* @method GET
*/
public function listAllVideoGames()
return new Response(Response::OK,$this->dao->getAllVideoGames());
/**
* @uri /videoGame/:id
* @json
* @provides application/json
* @method GET
*/
public function getVideoGame($id)
$vg = $this->dao->getVideoGame($id);
if ($vg)
return new Response(Response::OK,$vg);
else
throw new NotFoundException();
【问题讨论】:
【参考方案1】:我发现这样做的唯一方法是为 GET 调用创建一种调度程序,如下所示:
/**
* @uri /videoGame
* @uri /videoGame/:id
*/
class VideoGame extends Resource
protected function getDao()
return new VideoGameDao();
/**
* @uri /videoGame/:id
* @provides application/json
* @method GET
*/
public function getVideoGames($id = 0)
if (is_numeric($id) && $id > 0)
return $this->getVideoGame($id);
else
return $this->getAllVideoGames();
private function getVideoGame($id)
$vg = $this->dao->getVideoGame($id);
if ($vg)
return new Response(Response::OK,$vg);
else
throw new NotFoundException();
public function getAllVideoGames()
return new Response(Response::OK,$this->dao->getAllVideoGames());
【讨论】:
以上是关于Tonic.PHP 关于具有“/resource”和“/resource/id”URL 的的主要内容,如果未能解决你的问题,请参考以下文章
关于ssm的注解问题-@Autowired和@Resource的区别