尝试在类“Symfony \ Component \ HttpFoundation \ Response”上调用方法“getDoctrine”

时间:2015-05-05 09:23:34

标签: php symfony doctrine-orm

我一直在尝试为用户添加多辆车,但我总是收到此错误, 我已经在网上搜索了2天的答案,我仍然被卡住了 P.S。:我是Symfony和学说的新手

<?php

namespace CarsBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Doctrine\ORM\EntityRepository;

class CarsController extends Controller
{

    public function addCarsAction($iduser,$carName,$carPrice,$carVIN)
    {
        $cars = new cars();
        $cars->setPic('')
             ->setName($carName)
             ->setModle(Null)
             ->setPrice($carPrice)
             ->setVin($carVIN)
             ->setIdUser($iduser);
        //$this->forward('acme.controller.tagclass:ParseWebsite',array($categoryid));
            $em1 = $this->forward('app.cars_controller')
                        ->getDoctrine()->getManager()
                        ->getRepository('OBCarsTest1Bundle:cars')
                        ->persist($cars)
                        ->flush();
        }
        public function addCarsToUserAction()
        {       
            $this->addCarsAction(1,'bmw',45000,'o102384');
            //$this->addCarsAction(1,'mercedes',53000,'o224384');
            //$this->addCarsAction(1,'nisan',25000,'o686495');
            //$this->addCarsAction(2,'golf',44000,'o659826');
            //$this->addCarsAction(2,'toyota',23000,'o255325');

            //test if it works
            $repository = $this->getDoctrine()
                ->getRepository('OBCarsTest1Bundle:cars');      
            $cars = $repository->findOneById(3);

            return new Response('Created cars : \n '.$cars);
        }
    }

0 个答案:

没有答案