【发布时间】:2014-04-05 16:08:39
【问题描述】:
我正在尝试使用 fosrestBUndle 启动我的 REST API。我只是成功地运行了 GET。但是当我输入这个命令时,我遇到了 POST 显示错误“405 Method not allowed”
wget -S localhost/tutonew/web/app_dev.php/api/test/add
Controller 中的动作:
/**
* @Rest\View
* @Rest\Post("/api/test/add")
*
*/
public function postTestAction(Request $request) {
$entity = new Test();
$form = $this->createForm(new TestType(), $entity);
$form->bind($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($entity);
$em->flush();
return $this->redirectView(
$this->generateUrl(
'get_test', array('id' => $entity->getId())
), Codes::HTTP_CREATED
);
}
return array(
'form' => $form,
);
}
被调用的表单:
class TestType extends AbstractType {
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder
->add('field', 'text');
}
public function setDefaultOptions(OptionsResolverInterface $resolver) {
$resolver->setDefaults(array(
'data_class' => 'Minn\AdsAPIBundle\Entity\Test',
'csrf_protection' => false
));
}
public function getName() {
return 'test';
}
}
非常感谢您。
【问题讨论】:
标签: symfony doctrine-orm fosrestbundle