Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [Symfony2][Symfony] Błąd walidacji...
Forum PHP.pl > Forum > PHP > Frameworki
aras785
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:

  1. <?php
  2.  
  3. namespace Acme\Bundle\FrontBundle\Entity;
  4.  
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Symfony\Component\Validator\Constraint as Assert;
  7.  
  8. /**
  9.  * BrandFurniture
  10.  *
  11.  * @ORM\Table(name="brand_furniture")
  12.  * @ORM\Entity
  13.  */
  14. class BrandFurniture
  15. {
  16. /**
  17.   * @var string
  18.   *
  19.   * @ORM\Column(name="name", type="string", length=50, nullable=false)
  20.   */
  21. private $name;
  22.  
  23. /**
  24.   * @var string
  25.   *
  26.   * @ORM\Column(name="description", type="text", nullable=false)
  27.   */
  28. private $description;
  29.  
  30. /**
  31.   * @var string
  32.   *
  33.   * @ORM\Column(name="logo", type="string", length=50, nullable=false)
  34.   * @Assert\NotBlank()
  35.   */
  36. private $logo;
  37.  
  38. /**
  39.   * @var string
  40.   *
  41.   * @ORM\Column(name="website", type="string", length=100, nullable=false)
  42.   */
  43. private $website;
  44.  
  45. /**
  46.   * @var integer
  47.   *
  48.   * @ORM\Column(name="id", type="integer")
  49.   * @ORM\Id
  50.   * @ORM\GeneratedValue(strategy="IDENTITY")
  51.   */
  52. private $id;
  53.  
  54.  
  55.  
  56. /**
  57.   * Set name
  58.   *
  59.   * @param string $name
  60.   * @return BrandFurniture
  61.   */
  62. public function setName($name)
  63. {
  64. $this->name = $name;
  65.  
  66. return $this;
  67. }
  68.  
  69. /**
  70.   * Get name
  71.   *
  72.   * @return string
  73.   */
  74. public function getName()
  75. {
  76. return $this->name;
  77. }
  78.  
  79. /**
  80.   * Set description
  81.   *
  82.   * @param string $description
  83.   * @return BrandFurniture
  84.   */
  85. public function setDescription($description)
  86. {
  87. $this->description = $description;
  88.  
  89. return $this;
  90. }
  91.  
  92. /**
  93.   * Get description
  94.   *
  95.   * @return string
  96.   */
  97. public function getDescription()
  98. {
  99. return $this->description;
  100. }
  101.  
  102. /**
  103.   * Set logo
  104.   *
  105.   * @param string $logo
  106.   * @return BrandFurniture
  107.   */
  108. public function setLogo($logo)
  109. {
  110. $this->logo = $logo;
  111.  
  112. return $this;
  113. }
  114.  
  115. /**
  116.   * Get logo
  117.   *
  118.   * @return string
  119.   */
  120. public function getLogo()
  121. {
  122. return $this->logo;
  123. }
  124.  
  125. /**
  126.   * Set website
  127.   *
  128.   * @param string $website
  129.   * @return BrandFurniture
  130.   */
  131. public function setWebsite($website)
  132. {
  133. $this->website = $website;
  134.  
  135. return $this;
  136. }
  137.  
  138. /**
  139.   * Get website
  140.   *
  141.   * @return string
  142.   */
  143. public function getWebsite()
  144. {
  145. return $this->website;
  146. }
  147.  
  148. /**
  149.   * Get id
  150.   *
  151.   * @return integer
  152.   */
  153. public function getId()
  154. {
  155. return $this->id;
  156. }
  157. }

Controller:
  1. <?php
  2.  
  3. namespace Acme\Bundle\FrontBundle\Controller;
  4.  
  5. use Acme\Bundle\FrontBundle\Entity\BrandFurniture;
  6. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  7. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Response;
  10.  
  11. class StudiosController extends Controller
  12. {
  13. /**
  14.   * @Route("/")
  15.   */
  16. public function indexAction()
  17. {
  18. return new Response('Strona Główna');
  19. }
  20. /**
  21.   * Create
  22.   * @Route("/add")
  23.   */
  24. public function addAction(Request $request)
  25. {
  26. $brand = new BrandFurniture();
  27.  
  28. $form = $this->createFormBuilder($brand)
  29. ->add('name','text')
  30. ->add('description','text')
  31. ->add('logo','text')
  32. ->add('website','text')
  33. ->add('save','submit')
  34. ->getForm();
  35.  
  36. $form->handleRequest($request);
  37. if($form->isValid())
  38. {
  39. $em = $this->getDoctrine()->getManager();
  40. $em->persist($brand);
  41. $em->flush();
  42. return new Response('Dodane');
  43. }
  44. $build['form'] = $form->createView();
  45. return $this->render('AcmeFrontBundle:Studios:add.html.twig',$build);
  46. }
  47. }
Forti
Dostałeś treść błędu... 30 sec szukania w google:

use Symfony\Component\Validator\Constraints as Assert;
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.