Witam. Uczę się symfony2 i mam problem. Stworzyłem formularz do tworzenia rekordów w bazie i chciałem dodać do niego walidację w entity. Gdy nie było walidacji rekord się dodawał a gdy dodałem to wywala błąd:
Kod
[Semantical Error] The annotation "@Symfony\Component\Validator\Constraint\NotBlank" in property Acme\Bundle\FrontBundle\Entity\BrandFurniture::$logo does not exist, or could not be auto-loaded.
Proszę o pomoc
Entity:
<?php
namespace Acme\Bundle\FrontBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraint
as Assert;
/**
* BrandFurniture
*
* @ORM\Table(name="brand_furniture")
* @ORM\Entity
*/
class BrandFurniture
{
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=50, nullable=false)
*/
private $name;
/**
* @var string
*
* @ORM\Column(name="description", type="text", nullable=false)
*/
private $description;
/**
* @var string
*
* @ORM\Column(name="logo", type="string", length=50, nullable=false)
* @Assert\NotBlank()
*/
private $logo;
/**
* @var string
*
* @ORM\Column(name="website", type="string", length=100, nullable=false)
*/
private $website;
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* Set name
*
* @param string $name
* @return BrandFurniture
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set description
*
* @param string $description
* @return BrandFurniture
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Set logo
*
* @param string $logo
* @return BrandFurniture
*/
public function setLogo($logo)
{
$this->logo = $logo;
return $this;
}
/**
* Get logo
*
* @return string
*/
public function getLogo()
{
return $this->logo;
}
/**
* Set website
*
* @param string $website
* @return BrandFurniture
*/
public function setWebsite($website)
{
$this->website = $website;
return $this;
}
/**
* Get website
*
* @return string
*/
public function getWebsite()
{
return $this->website;
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
}
Controller:
<?php
namespace Acme\Bundle\FrontBundle\Controller;
use Acme\Bundle\FrontBundle\Entity\BrandFurniture;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class StudiosController extends Controller
{
/**
* @Route("/")
*/
public function indexAction()
{
return new Response('Strona Główna');
}
/**
* Create
* @Route("/add")
*/
public function addAction(Request $request)
{
$brand = new BrandFurniture();
$form = $this->createFormBuilder($brand)
->add('name','text')
->add('description','text')
->add('logo','text')
->add('website','text')
->add('save','submit')
->getForm();
$form->handleRequest($request);
if($form->isValid())
{
$em = $this->getDoctrine()->getManager();
$em->persist($brand);
$em->flush();
return new Response('Dodane');
}
$build['form'] = $form->createView();
return $this->render('AcmeFrontBundle:Studios:add.html.twig',$build);
}
}