Advertisement
djuro95

Symfony-hints

Feb 21st, 2019
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.64 KB | None | 0 0
  1. composer
  2.  
  3. create symfony project
  4.  
  5. composer create-project symfony/framework-standard-edition nameOfPROJECT
  6.  
  7. 1.enter
  8. 2.enter;
  9. 3.database name
  10. 4.database_username:root
  11. 5.database_password:root
  12. 6.enter
  13. 7.enter
  14. 8.enter
  15. 9.enter
  16. 10.enter
  17. ------------------------------
  18. run project
  19.  
  20. php bin/console server:run
  21.  
  22. ----------------------------
  23. format code
  24.  
  25. crtl+alt+f
  26.  
  27. izbacuje nekoristene stvari
  28.  
  29. ctrl+alt+o
  30.  
  31. crtl+x cut
  32.  
  33. -------------------------------
  34. php bin/console doctrine:scheme:create
  35.  
  36. php bin/console doctrine:scheme:drop --force
  37.  
  38. -------------------------------
  39. uvje na pocetku svakog viewa
  40.  
  41. {% extends 'base' %} - to je kostur naseg html
  42.  
  43. *****
  44.  
  45. {% block title %} ako u kosturu imamo ovaj blok ovako ga overajdujemo na novoj strani sa odgovarajucim sadrzajem
  46.  
  47. {% endblock %}
  48.  
  49. ******
  50.  
  51. {% for car in cars %}
  52. <tr>
  53. <td> {{car.make}}</td>
  54. <td> <a href=" url('show_car', {id: car.id } }}"> Show details</a> </td> //show_car je metoda u controleru
  55.  
  56. </tr>
  57. {% endfor %}
  58.  
  59.  
  60. ------------------------------
  61. Repository
  62.  
  63. Default controller
  64.  
  65. get cars from database
  66. $carRepository = $this->getDoctrine()->getRepository('CarBundle:Car');
  67. $cars = $carRepository->findAll();
  68.  
  69. -----------------------
  70.  
  71. field in class
  72.  
  73. /**
  74. * @var string
  75. * $ORM\Column(name=>"description", type="text", nullable=true)
  76. */
  77. private $description;
  78.  
  79.  
  80. moguce je u IDE koristiti komandu Getters and Setters
  81.  
  82. nakon promjene klase (u Entity) moramo izvsiti update Schema
  83.  
  84.  
  85. php bin/console doctrine:scheme:upadate --force
  86.  
  87.  
  88.  
  89. za pretragu po id koristimo (metoda u controlleru
  90.  
  91. /**
  92. * $param $id
  93. * @Route("/car/{id}", name="show_car")
  94. */
  95.  
  96. public function showAction()
  97. {
  98. $carRepository = $this->getDoctrine()->getRepository('CarBundle:Car');
  99. $car = $carRepository->find($id);
  100. return $this->render('CarBundle:Default:show.html.twig', ['car' => $car] );
  101. }
  102. -----------------------------
  103. extend and update existing entity
  104.  
  105. * $ORM\Column(name=>"price", type="float", scale=2) //scale je broj cifara iza decimalnog zareza
  106.  
  107.  
  108. generate getters and setters by console
  109.  
  110. php bin/console doctrine:generate:entities CarBundle
  111.  
  112. nakon toga da ti updejtovali bazu
  113.  
  114. php bin/console doctrine:scheme:upadate --force
  115.  
  116. **************
  117. u View
  118. <td>{% if car.navigation %}
  119. <span class="glyphicon glyphicon-ok"></span>
  120. {% else %}
  121. <span class="glyphicon glyphicon-remove"></span>
  122. {% endif %}
  123. </td>
  124.  
  125. -------------------------------------------
  126. One to many realtion between entities
  127.  
  128. php bin/console doctrine:generate:entity --entity="CarBundle:Make" --fields="name:string(255)"
  129. 1.enter
  130. 2.enter
  131. 3.enter
  132.  
  133.  
  134. ***************
  135. in Car class
  136.  
  137. /**
  138. * @var Model
  139. *
  140. * $ORM\ManyToOne(TargetEntity="CarBundle\Entity\Model", inversedBy="cars")
  141. */
  142. private $model;
  143.  
  144. ***************
  145. in Make class
  146.  
  147. /**
  148. * @var ArrayCollection
  149. *
  150. * $ORM\OneToMany(TargetEntity="CarBundle\Entity\Car", mappedBy="make")
  151. */
  152. private $cars;
  153.  
  154. *********************
  155. php bin/console doctrine:generate:entites CarBundle
  156.  
  157. php bin/console doctrine:scheme:upadate --force
  158.  
  159.  
  160.  
  161. ----------------------
  162.  
  163. {{ include ('micro-post/post.html.twig', {'post':post} ) }}
  164.  
  165. ----------------------
  166. flash messages
  167.  
  168. FlashBagInterface $flashBag
  169.  
  170.  
  171. $this->flashBag->add('notice',"Micro post was deleted');
  172.  
  173. {% for message in app.flashes('notice') %}
  174. <div class="alert-success">
  175. {{message}}
  176. </div>
  177. {% endfor %}
  178.  
  179. ---------------
  180. create user
  181.  
  182. php bin/console make:entity
  183.  
  184.  
  185. php bin/console doctrine:migration:diff
  186.  
  187.  
  188. php bin/console doctrine:migration:migrate
  189.  
  190.  
  191. php bin/console doctrine:fixtures:load
  192. y
  193.  
  194. stigao do 36 videa
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement