我正在尝试通过从我的 sencha touch 2 前端调用 put 方法来更新我的 mysql 数据库中的记录。我正在调用这个 url /api/users/id 但我不断收到 Symfony 错误:
No route found for "PUT /api/users/1
这就是我的 routing.yml 文件中的内容
users:
resource: "Acme\MainBundle\Controller\UsersController"
prefix: /api
type: rest
另外,我的 User* s *Controller中有 putUsersAction 设置
public function putUsersAction($id, Request $request)
{
$values['birthdate'] = $request->get('birthdate');
$values['clubid'] = $request->get('clubid');
$em = $this->getDoctrine()->getEntityManager();
$user = $this->getDoctrine()
->getRepository('AcmeMainBundle:User')
->find($id);
$club = $this->getDoctrine()
->getRepository('AcmeMainBundle:Club')
->find($values['clubid']);
$user->setBirthdate($values['birthdate']);
$user->addClub($club);
$em->flush();
$view = View::create()
->setStatusCode(200)
->setData($user);
return $this->get('fos_rest.view_handler')->handle($view);
}
为什么 Symfony 告诉我没有 PUT /api/users/id 路由?
编辑 1:路由器:调试输出
[router] Current routes
Name Method Pattern
_wdt ANY /_wdt/{token}
_profiler_search ANY /_profiler/search
_profiler_purge ANY /_profiler/purge
_profiler_info ANY /_profiler/info/{about}
_profiler_import ANY /_profiler/import
_profiler_export ANY /_profiler/export/{token}.txt
_profiler_phpinfo ANY /_profiler/phpinfo
_profiler_search_results ANY /_profiler/{token}/search/results
_profiler ANY /_profiler/{token}
_profiler_redirect ANY /_profiler/
_configurator_home ANY /_configurator/
_configurator_step ANY /_configurator/step/{index}
_configurator_final ANY /_configurator/final
get_users GET /api/users.{_format}
post_users POST /api/users.{_format}
get_clubs GET /api/clubs.{_format}
post_clubs POST /api/clubs.{_format}
put_users PUT /api/users.{_format}