[英]Two methods for the same route (one with parameters, the other without) with FOSRestBundle
我正在嘗試使用FOSRestBundle和Symfony的兩個不同功能使用相同的路由。 這是我所擁有的:
/**
* @Rest\Get("/users")
* @QueryParam(name="login")
*/
public function getLoginAvailability(ParamFetcher $paramFetcher)
{
return $this->_checkLoginAvailability($paramFetcher->get('login'));
}
/**
* @Rest\Get("/users")
*/
public function otherFunc()
{
return "other";
}
問題是:當我通過HTTP GET請求(為它提供登錄參數)調用第一個函數時,它正在執行第二個函數,而忽略了第一個函數。 有什么建議嗎?
為什么不通過檢查您的參數是否已設置並根據結果返回您想要的結果來處理它呢?
/**
* @Rest\Get("/users")
* @QueryParam(name="login")
*/
public function getLoginAvailability(ParamFetcher $paramFetcher)
{
$params = $paramFetcher->all();
if (array_key_exists('login', $params)) {
return $this->_checkLoginAvailability($params['login']);
} else {
return $this->otherFunc();
}
private function otherFunc()
{
return "other";
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.