我們在Symfony2中使用下面的包來創建一個RESTful API。控制器必須返回一個響應(對象(Symfony Component Form Form)給出)
new FOS\RestBundle\FOSRestBundle(),
new JMS\SerializerBundle\JMSSerializerBundle(),
new Nelmio\ApiDocBundle\NelmioApiDocBundle(),
我們得到下面的錯誤運行PHP後composer.phar更新
[2014-12-05 10:39:41] security.INFO: Populated SecurityContext with an anonymous Token [] []
[2014-12-05 10:39:41] request.CRITICAL: Uncaught PHP Exception LogicException: "The controller must return a response (Object(Symfony\Component\Form\Form) given)." at /var/www/html/symfony2/app/bootstrap.php.cache line 3020 {"exception":"[object] (LogicException: The controller must return a response (Object(Symfony\\Component\\Form\\Form) given). at /var/www/html/symfony2/app/bootstrap.php.cache:3020)"} []
[2014-12-05 10:39:41] security.DEBUG: Write SecurityContext in the session [] []
我們使用以下步驟
//install symfony
php composer.phar create-project symfony/framework-standard-edition symfony2/
//move composer into symfony folder
cp composer.phar symfony2/composer.phar
rm composer.phar
cd symfony2
//symfony dependencies
php composer.phar require doctrine/doctrine-fixtures-bundle
php composer.phar require "friendsofsymfony/rest-bundle" "@dev"
php composer.phar require "jms/serializer-bundle" "@dev"
php composer.phar require "nelmio/api-doc-bundle" "@dev"
的API請求將返回500服務器在我們的服務器上安裝的Symfony2錯誤。
由於我不確定它爲什麼不起作用,我已經將錯誤追溯到下面的點。
@Annotations\View(
templateVar = "form"
)
ClassResourceInterface類負責以上操作。
這可能涉及到這個問題,但在此發佈的解決方案不起作用:
FOSRestBundle: The controller must return a response (Array()) given
東西是不對的類:
Nelmio\ApiDocBundle\Annotation\ApiDoc
有沒有人有這個問題,因爲好?
謝謝
什麼的'Annotations'別名您使用的語句? – 2014-12-06 19:25:05
@WouterJ你用什麼聲明來表示? – pppglowacki 2014-12-08 08:18:46