Tôi đang cố gắng sử dụng Symfony2 và FOSRestBundle để tìm ra một khung công tác REST và tôi thất bại thảm hại.Không thể làm việc với FOSRestBundle
Tôi đã làm như sau:
trong DEPS tập tin của tôi:
[FOSRest]
git=git://github.com/FriendsOfSymfony/FOSRest.git
target=fos/FOS/Rest
[FOSRestBundle]
git=git://github.com/FriendsOfSymfony/FOSRestBundle.git
target=bundles/FOS/RestBundle
[JMSSerializerBundle]
git=git://github.com/schmittjoh/JMSSerializerBundle.git
target=bundles/JMS/SerializerBundle
Trong ứng dụng của tôi/config.yml
fos_rest:
view:
formats:
rss: true
xml: false
templating_formats:
html: true
force_redirects:
html: true
failed_validation: HTTP_BAD_REQUEST
default_engine: twig
sensio_framework_extra:
view:
annotations: false
Trong điều khiển của tôi:
namespace Rest\WebServiceBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use FOS\RestBundle\View\View;
class DefaultController extends Controller
{
public function indexAction($name)
{
$view = View::create()
->setStatusCode(200)
->setData($name);
return $this->get('fos_rest.view_handler')->handle($view);
}
}
Khi tôi truy cập URL: http://local.symfony.com/web/app_dev.php/hello/test
tôi nhận được:
Unable to find template "".
500 Internal Server Error - InvalidArgumentException
2 linked Exceptions: Twig_Error_Loader » Twig_Error_Loader
Các tài liệu có vẻ khó hiểu đối với tôi và tôi không thể tiếp tục. Tất cả những gì tôi muốn là có thể truyền một mảng dữ liệu đến bộ điều khiển và lấy lại một định dạng JSON. Ai đó có thể giúp đỡ?
Tôi cũng gặp sự cố khi thực hiện việc này. Nó có vẻ khá khó hiểu cho những gì có vẻ giống như một nhiệm vụ tương đối đơn giản. Bạn đã có may mắn với nó chưa? – greg