控制器必须返回响应500内部服务器错误 - LogicException

时间:2015-05-29 15:25:52

标签: php symfony

自一周以来无法找到解决此问题的方法:'(

  

控制器必须返回响应(Array(order =>   对象(Bull \ LogisticBundle \ Entity \ Order),form =>   对象(Symfony \ Component \ Form \ FormView),postRoute =>   给予/taz/web/app_dev.php/fr/spareordered/create/1)。 500内部   服务器错误 - LogicException

这是我的控制器:

namespace Taz\LogisticBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Taz\LogisticBundle\Entity\SparepartOrdered;
use Taz\LogisticBundle\Form\SparepartOrderedType;

/**
 * SparepartOrderedController controller.
 *
 * @Route("/spareordered")
 *
 * @SuppressWarnings(PHPMD)
 */
class SparepartOrderedController extends LogisticController
{



     const CONTEXT = 'SparepartOrdered';

        /**
         * Return the new SparepartOrdered form.
         *
         * @param int $orderId the order id
         *
         * @return array view parameters
         *
         * @Route("/new/{orderId}", name="sparepartordered_new")
         */
        public function newAction($orderId)
        {
            $this->writeLog();
            $order = $this->getOrderRepository()->find($orderId);

            if (!$order) {
                throw $this->createNotFoundException('Unable to find Order entity.');
            }

            $sparepartOrdered = new SparepartOrdered();
            $form = $this->createSparepartOrderedForm($sparepartOrdered);

            $postRoute = $this->generateUrl(
                'sparepartordered_create',
                array('orderId' => $order->getId())
            );

            return array(
                'order'     => $order,
                'form'      => $form->createView(),
                'postRoute' => $postRoute
            );
        }

/**
     * Creates a new SparepartOrdered entity.
     *
     * @param Request $request    the request
     * @param int     $orderId    the order id
     *
     * @return array view parameters
     *
     * @Route("/create/{orderId}", name="sparepartordered_create")
     * @Method("POST")
     * @Template("TazLogisticBundle:SparepartOrdered:new.html.twig")
     */
    public function createSparepartAction(Request $request, $orderId)
    {
        $this->writeLog();
        $order = $this->getOrderRepository()->find($orderId);

        if (!$order) {
            throw $this->createNotFoundException(
                'Unable to find Order entity.'
            );
        }

        $sparepartOrdered = new SparepartOrdered();
        $form = $this->createSparepartOrderedForm($sparepartOrdered);
        $form->handleRequest($request);

        $sparepartOrdered->setOrder($order);

        if ($form->isValid()) {

            $eManager = $this->getDoctrine()->getManager();
            $eManager->persist($sparepartOrdered);
            $eManager->persist($order);
            $eManager->flush();

            $this->setFlashNotice('success.sparepartordered.created');

            return $this->redirect(
                    $this->generateUrl('order_edit',
                                       array('entityId' => $order->getId()))
            );
        } else {
            $postRoute = $this->generateUrl(
                'sparepartordered_create',
                array('orderId' => $order->getId())
            );

            return array(
                'order'  => $order,
                'form'      => $form->createView(),
                'postRoute' => $postRoute
            );
        }
    }

    /**
     * Create the SparepartOrdered Form
     *
     * @param type $entity the SparepartOrdered to map to the form
     *
     * @return SparepartOrderedType the form
     */
    private function createSparepartOrderedForm($entity)
    {
        $this->writeLog();

        return $this->createForm(
                new SparepartOrderedType(), $entity,
                array(
                'em'           => $this->getDoctrine()->getManager()
                )
        );
    }

我的实体和存储库运行完美。所有基于此主题的解决方法都无法解决此问题。

感谢您的帮助!

此致

1 个答案:

答案 0 :(得分:1)

错误是明确的:.network.VolleyNetwork

如果您只想返回参数数组并利用the controller must return a response注释,则必须将其添加到@template方法的注释中,就像您对其他操作一样