Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [SF2][SF][Symfony2] Metoda w entity
Forum PHP.pl > Forum > PHP > Frameworki
aras785
Cześć.

Mam takie entity:

  1. <?php
  2.  
  3. namespace Acme\Bundle\AdminBundle\Entity;
  4.  
  5. use Cocur\Slugify\Slugify;
  6. use Doctrine\ORM\EntityManager;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9.  
  10. /**
  11.  * BrandDevice
  12.  *
  13.  * @ORM\Table(name="brand_device")
  14.  * @ORM\Entity
  15.  */
  16. class BrandDevice
  17. {
  18. /**
  19.   * @var string
  20.   *
  21.   * @ORM\Column(name="name", type="string", length=50, nullable=false)
  22.   * @Assert\NotBlank(message="Te pole jest wymagane")
  23.   */
  24. private $name;
  25.  
  26. /**
  27.   * @var string
  28.   *
  29.   * @ORM\Column(name="description", type="text", nullable=false)
  30.   */
  31. private $description;
  32.  
  33. /**
  34.   * @var string
  35.   *
  36.   * @ORM\Column(name="logo", type="string", length=50, nullable=false)
  37.   */
  38. private $logo;
  39.  
  40. /**
  41.   * @var string
  42.   *
  43.   * @ORM\Column(name="website", type="string", length=100, nullable=false)
  44.   * @Assert\NotBlank(message="Te pole jest wymagane")
  45.   * @Assert\Url(message="Proszę podać poprawny adres strony www")
  46.   */
  47. private $website;
  48.  
  49. /**
  50.   * @var integer
  51.   *
  52.   * @ORM\Column(name="id", type="integer")
  53.   * @ORM\Id
  54.   * @ORM\GeneratedValue(strategy="IDENTITY")
  55.   */
  56. private $id;
  57.  
  58.  
  59. private $entityManager;
  60.  
  61. public function __construct(EntityManager $entityManager)
  62. {
  63. $this->entityManager = $entityManager;
  64. }
  65. /**
  66.   * Set name
  67.   *
  68.   * @param string $name
  69.   * @return BrandDevice
  70.   */
  71. public function setName($name)
  72. {
  73. $this->name = $name;
  74.  
  75. return $this;
  76. }
  77.  
  78. /**
  79.   * Get name
  80.   *
  81.   * @return string
  82.   */
  83. public function getName()
  84. {
  85. return $this->name;
  86. }
  87.  
  88. /**
  89.   * Set description
  90.   *
  91.   * @param string $description
  92.   * @return BrandDevice
  93.   */
  94. public function setDescription($description)
  95. {
  96. $this->description = $description;
  97.  
  98. return $this;
  99. }
  100.  
  101. /**
  102.   * Get description
  103.   *
  104.   * @return string
  105.   */
  106. public function getDescription()
  107. {
  108. return $this->description;
  109. }
  110.  
  111. /**
  112.   * Set logo
  113.   *
  114.   * @param string $logo
  115.   * @return BrandDevice
  116.   */
  117. public function setLogo($logo)
  118. {
  119. $this->logo = $logo;
  120.  
  121. return $this;
  122. }
  123.  
  124. /**
  125.   * Get logo
  126.   *
  127.   * @return string
  128.   */
  129. public function getLogo()
  130. {
  131. return $this->logo;
  132. }
  133.  
  134. /**
  135.   * Set website
  136.   *
  137.   * @param string $website
  138.   * @return BrandDevice
  139.   */
  140. public function setWebsite($website)
  141. {
  142. $this->website = $website;
  143.  
  144. return $this;
  145. }
  146.  
  147. /**
  148.   * Get website
  149.   *
  150.   * @return string
  151.   */
  152. public function getWebsite()
  153. {
  154. return $this->website;
  155. }
  156.  
  157. /**
  158.   * Get id
  159.   *
  160.   * @return integer
  161.   */
  162. public function getId()
  163. {
  164. return $this->id;
  165. }
  166.  
  167. public function findLikeName($term)
  168. {
  169. $qb = $this->entityManager->createQueryBuilder();
  170. $result = $qb->select('n')->from('AcmeAdminBundle:BrandDevice', 'n')
  171. ->where( $qb->expr()->like('n.name', $qb->expr()->literal('%' . $term . '%')) )
  172. ->getQuery()
  173. ->getResult();
  174. return $result;
  175. }
  176.  
  177.  
  178. }
  179.  


i w controlerze daje:

  1. ...
  2. $brand = new BrandDevice();
  3. $brand->findLikeName('asd');
  4. ...


dostaję zwrotkę, że nie ma takiej metody: findLikeName

Wiecie dlaczego tak się dzieje?

Pzdr.
ohm
Entity manager w entity, tego jeszcze nie widziałem wink.gif
Od takich rzeczy jest repository:
http://symfony.com/doc/current/book/doctri...ository-classes
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.