【发布时间】:2014-05-29 08:13:41
【问题描述】:
我正在尝试使用最新的 Symfony (2.4.5) 和 FOSRestBundle (dev-master 6b384c1) 引导简单的 REST 应用程序。
我的配置:
fos_rest:
format_listener: true
view:
view_response_listener: true
sensio_framework_extra:
view: { annotations: false }
router: { annotations: true }
我的路线:
products:
type: rest
resource: Telemetrik\Bundle\ProductBundle\Controller\ProductsController
控制器:
<?php
// namespace & imports
class ProductsController extends Controller
{
/**
* @return Form
* @View("TelemetrikProductBundle::form.html.twig")
*/
public function newProductAction()
{
return $this->getForm();
}
/**
* @param Request $request
* @return View|Form
* @View
*/
public function postProductsAction(Request $request)
{
$form = $this->getForm();
$form->handleRequest($request);
if ($form->isValid()) {
// Logic placeholder
}
return $form;
}
protected function getForm()
{
return $this->createForm(new ProductType());
}
}
当使用router:debug 我得到:
new_product GET ANY ANY /products/new.{_format}
post_products POST ANY ANY /products.{_format}
这很好,但是因为newProductAction 应该是一种形式:
- 我不希望它可以从 HTML 以外的格式访问
- 我想从
/products/new而不是/products/new.html访问我的表单(这似乎是我可以访问该资源的唯一选项)。如果我去products/new我得到:Format '' not supported, handler must be implemented
【问题讨论】:
标签: php symfony fosrestbundle