Symfony problem z wyszukiwaniem |
Symfony problem z wyszukiwaniem |
6.05.2018, 11:40:23
Post
#1
|
|
Grupa: Zarejestrowani Postów: 3 Pomógł: 0 Dołączył: 6.05.2018 Ostrzeżenie: (0%) |
Witam, mam mały problem. Mianowicie mam encje Advert z ogloszeniami, jest poalczona relacja jeden do wielu z encja Address, natomiast Address tez jest relacja jeden do wielu z encja City.
Probuje zrobic wyszukiwarke, w zmiennejj $selectedCity dobrze mi pobiera ID miasta natomiast pozniej jest jakas lipa searchController ma 1 akcje: Cytat /** * @Route("/search/city", name="search_city") * * @param Request $request * @return \Symfony\Component\HttpFoundation\Response */ public function searchCityAction(Request $request) { $search = new City(); $form = $this->createForm(CityType::class, $search) ->add('submit', SubmitType::class, ["label" => "Szukaj"]); $entityManager = $this->getDoctrine()->getManager(); if($request->isMethod(Request::METHOD_POST)) { $form->handleRequest($request); $selectedCity = ($_REQUEST['city']['city']); $address = $entityManager->getRepository(Address::class)->findBy(["city" => $selectedCity]); $searched = $entityManager->getRepository(Advert::class)->findBy(["address" => $address]); return $this->render("Search/searched.html.twig", ["searched" => $searched]); } return $this->render("Search/index.html.twig", ["form" => $form->createView()]); } Dostalem jedna rade zmienic controller tak: Cytat /** * @Route("/search/city", name="search_city") * * @param Request $request * @return \Symfony\Component\HttpFoundation\Response */ public function searchCityAction(Request $request) { $search = new City(); $form = $this->createForm(CityType::class, $search) ->add('submit', SubmitType::class, ["label" => "Szukaj"]); $entityManager = $this->getDoctrine()->getManager(); if($request->isMethod(Request::METHOD_POST)) { $form->handleRequest($request); $selectedCity = ($_REQUEST['city']['city']); $address = $entityManager->getRepository(Address::class)->findBy(["city" => $selectedCity]); $addressIds = $address->map(function($single_address) { return $single_address->id; }); $searched = $entityManager->getRepository(Advert::class)->findBy(["address" => $addressIds]); return $this->render("Search/searched.html.twig", ["searched" => $searched]); } return $this->render("Search/index.html.twig", ["form" => $form->createView()]); } Tylko ze przy takim rozwiazaniu dostaje errora: Cytat Call to a member function map() on array Wie ktos moze co moze byc nie tak? |
|
|
6.05.2018, 12:27:24
Post
#2
|
|
Grupa: Zarejestrowani Postów: 8 068 Pomógł: 1414 Dołączył: 26.10.2005 Ostrzeżenie: (0%) |
|
|
|
6.05.2018, 12:40:56
Post
#3
|
|
Grupa: Zarejestrowani Postów: 3 Pomógł: 0 Dołączył: 6.05.2018 Ostrzeżenie: (0%) |
No i? Masz dokładny komunikat błędu. $address jest tablicą obiektów a nie obiektem typu Iterator. Tak powinno wyglądać
Super działa dzieki, tylko trzeba bylo jeszcze ten return $single_address->id zmienic na $single_address->getId() bo krzyczal ze id jest prywatna Ten post edytował paprikano 6.05.2018, 13:06:07 |
|
|
Wersja Lo-Fi | Aktualny czas: 26.04.2024 - 11:33 |