Advertisement
Guest User

Untitled

a guest
Dec 14th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.97 KB | None | 0 0
  1. Всичко работи правилно, записва се като хората ролята.
  2. Ето Ентито User:
  3. =================================
  4. <?php
  5.  
  6. namespace AppBundle\Entity;
  7.  
  8. use AppBundle\AppBundle;
  9. use AppBundle\Controller\SecurityController;
  10. use AppBundle\Repository\RoleRepository;
  11. use Doctrine\Common\Collections\ArrayCollection;
  12. use Doctrine\Common\Collections\Collection;
  13. use Doctrine\ORM\Mapping as ORM;
  14. use Symfony\Component\Security\Core\User\UserInterface;
  15. use AppBundle\Entity\User;
  16. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  17. use AppBundle\Repository;
  18.  
  19.  
  20. /**
  21. * User
  22. *
  23. * @ORM\Table(name="users")
  24. * @ORM\Entity(repositoryClass="AppBundle\Repository\UserRepository")
  25. */
  26. class User implements UserInterface, \Serializable
  27. {
  28. /**
  29. * @var int
  30. *
  31. * @ORM\Column(name="id", type="integer")
  32. * @ORM\Id
  33. * @ORM\GeneratedValue(strategy="AUTO")
  34. */
  35. private $id;
  36.  
  37. /**
  38. * @var string
  39. *
  40. * @ORM\Column(name="userName", type="string", length=255, unique=true)
  41. */
  42. private $userName;
  43. /**
  44. * @var string
  45. */
  46. private $plainPassword;
  47. /**
  48. * @var string
  49. *
  50. * @ORM\Column(name="password", type="string", length=255)
  51. */
  52. private $password;
  53.  
  54. /**
  55. * @var string
  56. *
  57. * @ORM\Column(name="fullName", type="string", length=255)
  58. */
  59. private $fullName;
  60.  
  61. /**
  62. * @var string
  63. *
  64. * @ORM\Column(name="email", type="string", length=255, unique=true)
  65. */
  66. private $email;
  67. /**
  68. * @var decimal
  69. *
  70. * @ORM\Column(name="cash", type="decimal", precision=10, scale=2)
  71. */
  72. private $cash;
  73.  
  74. /**
  75. * @var decimal
  76. *
  77. * @ORM\Column(name="usedCash", type="decimal", precision=10, scale=2)
  78. */
  79. private $usedCash;
  80.  
  81. /**
  82. * @var datetime
  83. *
  84. * @ORM\Column(name="registerDate", type="datetime")
  85. */
  86. private $registerDate;
  87.  
  88. /**
  89. * @var bool
  90. *
  91. * @ORM\Column(name="isBanned", type="boolean", nullable=true)
  92. */
  93. private $isBanned;
  94.  
  95. /**
  96. * @ORM\ManyToMany(targetEntity="AppBundle\Entity\Role")
  97. * @ORM\JoinTable(name="user_roles",
  98. * joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
  99. * inverseJoinColumns={@ORM\JoinColumn(name="role_id", referencedColumnName="id")})
  100. * @var Collection|Role[]
  101. */
  102. private $roles;
  103.  
  104. /**
  105. * User constructor.
  106. */
  107. public function __construct()
  108. {
  109. $this->roles = new ArrayCollection();
  110. }
  111.  
  112.  
  113. /**
  114. * Get id
  115. *
  116. * @return int
  117. */
  118. public function getId()
  119. {
  120. return $this->id;
  121. }
  122.  
  123. /**
  124. * Set userName
  125. *
  126. * @param string $userName
  127. *
  128. * @return User
  129. */
  130. public function setUserName($userName)
  131. {
  132. $this->userName = $userName;
  133.  
  134. return $this;
  135. }
  136.  
  137. /**
  138. * Get userName
  139. *
  140. * @return string
  141. */
  142. public function getUserName()
  143. {
  144. return $this->userName;
  145. }
  146.  
  147. /**
  148. * Set password
  149. *
  150. * @param string $password
  151. *
  152. * @return User
  153. */
  154. public function setPassword($password)
  155. {
  156. $this->password = $password;
  157.  
  158. return $this;
  159. }
  160.  
  161. /**
  162. * Get password
  163. *
  164. * @return string
  165. */
  166. public function getPassword()
  167. {
  168. return $this->password;
  169. }
  170.  
  171. /**
  172. * Set fullName
  173. *
  174. * @param string $fullName
  175. *
  176. * @return User
  177. */
  178. public function setFullName($fullName)
  179. {
  180. $this->fullName = $fullName;
  181.  
  182. return $this;
  183. }
  184.  
  185. /**
  186. * Get fullName
  187. *
  188. * @return string
  189. */
  190. public function getFullName()
  191. {
  192. return $this->fullName;
  193. }
  194.  
  195. /**
  196. * Set email
  197. *
  198. * @param string $email
  199. *
  200. * @return User
  201. */
  202. public function setEmail($email)
  203. {
  204. $this->email = $email;
  205.  
  206. return $this;
  207. }
  208.  
  209. /**
  210. * Get email
  211. *
  212. * @return string
  213. */
  214. public function getEmail()
  215. {
  216. return $this->email;
  217. }
  218.  
  219. /**
  220. *
  221. */
  222. public function getRoles()
  223. {
  224. $roles = [];
  225. foreach ($this->roles as $role){
  226. $roles[] = $role->getName();
  227. }
  228. return $roles;
  229.  
  230. }
  231.  
  232. public function setRoles($role){
  233. $this->roles = null;
  234. $this->roles[] = $role;
  235. return $this;
  236. }
  237.  
  238.  
  239. /**
  240. * Returns the salt that was originally used to encode the password.
  241. *
  242. * This can return null if the password was not encoded using a salt.
  243. *
  244. * @return string|null The salt
  245. */
  246. public function getSalt()
  247. {
  248. // TODO: Implement getSalt() method.
  249. }
  250.  
  251. /**
  252. * Removes sensitive data from the user.
  253. *
  254. * This is important if, at any given point, sensitive information like
  255. * the plain-text password is stored on this object.
  256. */
  257. public function eraseCredentials()
  258. {
  259. // TODO: Implement eraseCredentials() method.
  260. }
  261. public function serialize()
  262. {
  263. return serialize([
  264. $this->getId(),
  265. $this->getUserName(),
  266. $this->getPassword()
  267. ]);
  268. }
  269. public function unserialize($serialized)
  270. {
  271. list(
  272. $this->id,
  273. $this->userName,
  274. $this->password
  275. ) = unserialize($serialized);
  276. }
  277.  
  278. /**
  279. * @return string
  280. */
  281. public function getPlainPassword(): string
  282. {
  283. return $this->plainPassword.'';
  284. }
  285.  
  286. /**
  287. * @param string $plainPassword
  288. */
  289. public function setPlainPassword(string $plainPassword)
  290. {
  291. $this->plainPassword = $plainPassword;
  292. }
  293. /**
  294. * @return decimal
  295. */
  296. public function getCash()
  297. {
  298. return $this->cash;
  299. }
  300.  
  301. /**
  302. * @param decimal $cash
  303. */
  304. public function setCash($cash)
  305. {
  306. $this->cash = $cash;
  307. }
  308. /**
  309. * @return decimal
  310. */
  311. public function getUsedCash()
  312. {
  313. return $this->usedCash;
  314. }
  315.  
  316. /**
  317. * @param decimal $usedCash
  318. */
  319. public function setUsedCash($usedCash)
  320. {
  321. $this->usedCash = $usedCash;
  322. }
  323.  
  324. /**
  325. * @return datetime
  326. */
  327. public function getRegisterDate()
  328. {
  329. return $this->registerDate;
  330. }
  331.  
  332. /**
  333. * @param datetime $registerDate
  334. */
  335. public function setRegisterDate($registerDate)
  336. {
  337. $this->registerDate = $registerDate;
  338. }
  339.  
  340. /**
  341. * @return mixed
  342. */
  343. public function getisBanned()
  344. {
  345. return $this->isBanned;
  346. }
  347.  
  348. /**
  349. * @param mixed $isBanned
  350. */
  351. public function setIsBanned($isBanned)
  352. {
  353. $this->isBanned = $isBanned;
  354. }
  355.  
  356. }
  357.  
  358. ====================================
  359. Eто и ентито на ролите:
  360. <?php
  361.  
  362. namespace AppBundle\Entity;
  363.  
  364. use Doctrine\ORM\Mapping as ORM;
  365.  
  366. /**
  367. * Role
  368. *
  369. * @ORM\Table(name="roles")
  370. * @ORM\Entity(repositoryClass="AppBundle\Repository\RoleRepository")
  371. */
  372. class Role
  373. {
  374. /**
  375. * @var int
  376. *
  377. * @ORM\Column(name="id", type="integer")
  378. * @ORM\Id
  379. * @ORM\GeneratedValue(strategy="AUTO")
  380. */
  381. private $id;
  382.  
  383. /**
  384. * @var string
  385. *
  386. * @ORM\Column(name="name", type="string", length=255, unique=true)
  387. */
  388. private $name;
  389.  
  390.  
  391. /**
  392. * Get id
  393. *
  394. * @return int
  395. */
  396. public function getId()
  397. {
  398. return $this->id;
  399. }
  400.  
  401. /**
  402. * Set name
  403. *
  404. * @param string $name
  405. *
  406. * @return Role
  407. */
  408. public function setName($name)
  409. {
  410. $this->name = $name;
  411.  
  412. return $this;
  413. }
  414.  
  415. /**
  416. * Get name
  417. *
  418. * @return string
  419. */
  420. public function getName()
  421. {
  422. return $this->name;
  423.  
  424. }
  425.  
  426.  
  427. }
  428.  
  429.  
  430. =======================================
  431.  
  432. Ето и twig-a:
  433. {% extends 'base.html.twig' %}
  434. {% block body %}
  435. <div class="container-fluid">
  436. <div class="row-fluid">
  437. <div class="span4"></div>
  438. <!--/span-->
  439. <div class="span4" align="center">
  440. <div class="hero-unit" align="center">
  441. {{ form_start(form) }}
  442. {{ form_widget(form) }}
  443. {{ form_end(form) }}
  444. <br /><br />
  445. <a href="{{ path('user_profile') }}">Go back to your profile</a>
  446. </div>
  447. </div>
  448. <!-- /span -->
  449. <div class="span4"></div>
  450. </div>
  451. <!-- /row -->
  452. </div>
  453. {% endblock %}
  454. ===========================================
  455. Не искам давам линк към github за да не ми изкопира някой проекта, все пак е супер-дупер як :D
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement