Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Service
- + +
- kreiramo CarBundle/Service/DataChecker.php
- public function checkCar(Car $car)
- {
- return "Car " . $car->getModel() . " checked";
- }
- *************************
- CarBundle/Resouce/config/services.yml
- services:
- car.data_checker:
- class: CarBundle\Service\DataChecker
- ******************************
- CarController
- /**
- * @param $id
- * Promote a car
- * @Route("/promote/{id}", name="car_promote")
- */
- public function promoteAction($id)
- {
- return $this->redirectToRoute("car_index");
- }
- ***********************
- View index.html.twig
- <a href="{{ path('car_promote', {'id' : car.id}) }}">promote</a>
- ----------------------------
- CarContoler
- /**
- * @param $id
- * Promote a car
- * @Route("/promote/{id}", name="car_promote")
- */
- public function promoteAction($id)
- {
- $dataChecker = $this->get('car.data_checker');
- $em = $this->getDoctrine()->getEntityManager();
- $car = $em->getRepository('CarBundle:Car')->find($id);
- $result = $dataChcker->checkCar($car);
- $this->addFlash('success', $result);
- return $this->redirectToRoute("car_index");
- }
- ****************************
- base.html.twig
- {% for type, flashes in app.session.flashbag.all %}
- {% for flash in flashes %}
- <div class="alert alert-{{ type }} fade in">
- {{ flash }}
- </div>
- {% endfor %}
- {% endfor %}
- -------------------------------------
- class DataChecker
- /** @var EntityManager
- protected $entityManager;
- /**
- *DataChecker constructor
- *
- * @param EntityManger $entityManger
- */
- public function __construction($entityManager)
- {
- $this->entityManager = $entityManger;
- }
- ******************
- CarBundle/Resouce/config/services.yml
- services:
- car.data_checker:
- class: CarBundle\Service\DataChecker
- arguments: ["@doctrine.orm.entity_manager"]
Add Comment
Please, Sign In to add comment