Api &引用;命名空间“”没有注册路径;应用程序"&引用;FosRestBundle、Symfony、POST/DELETE
在对我的API执行post或delete请求时,我收到这样一条消息“没有命名空间“App”的注册路径”。找到工作。我用FosUserBundle config.yml PersonRestController.php 错误: 我已经检查了我的config.yml。它没有重复显示。Api &引用;命名空间“”没有注册路径;应用程序"&引用;FosRestBundle、Symfony、POST/DELETE,api,symfony,twig,fosrestbundle,Api,Symfony,Twig,Fosrestbundle,在对我的API执行post或delete请求时,我收到这样一条消息“没有命名空间“App”的注册路径”。找到工作。我用FosUserBundle config.yml PersonRestController.php 错误: 我已经检查了我的config.yml。它没有重复显示。 尽管有错误,POST方法仍然有效,但是DELETE不起作用。在use语句中,您似乎使用了App\而不是AppBundle\(同时检查您的配置文件) 确保在config.yml中包含以下行: 您还应该扩展FOSRest
尽管有错误,POST方法仍然有效,但是DELETE不起作用。在
use
语句中,您似乎使用了App\
而不是AppBundle\
(同时检查您的配置文件)
确保在config.yml中包含以下行:
您还应该扩展FOSRestController
,而不是使用Trait()
NB:我假设您使用AppBundle
作为主捆绑包,因为您在config.xml中将其用于keyexception\u controller
...
fos_rest:
body_converter:
enabled: true
validate: true
validation_errors_argument: validationErrors
exception:
enabled: true
exception_controller: 'AppBundle\Controller\ExceptionController::showAction'
param_fetcher_listener: true
routing_loader:
default_format: json
include_format: false
serializer:
serialize_null: true
view:
view_response_listener: force
...
...
class PersonRestController extends AbstractController {
use ControllerTrait;
/**
* @Rest\View()
*/
public function getPersonsAction() {
$data = $this->getDoctrine()
->getRepository(Person::class)
->findAll();
return $data;
}
/**
* @Rest\View(statusCode=201)
* @ParamConverter("person", converter="fos_rest.request_body")
* @Rest\NoRoute()
*/
public function postPersonsAction(Person $person, ConstraintViolationListInterface $validationErrors) {
if (count($validationErrors) > 0) {
throw new ValidationException($validationErrors);
}
$em = $this->getDoctrine()->getManager();
$em->persist($person);
$em->flush();
return $person;
}
/**
* @Rest\View()
*/
public function deletePersonsAction(?Person $person) {
if($person === null) {
return $this->view(null, 404);
}
$em = $this->getDoctrine()->getManager();
$em->remove($person);
$em->flush();
return null;
}
/**
* @Rest\View()
*/
public function getPersonAction(?Person $person) {
if($person === null) {
return $this->view(null, 404);
}
return $person;
}
}
...
templating:
engines: ['twig']