Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Symfony problem z wyszukiwaniem
paprikano
post
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 sad.gif
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?
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 19.08.2025 - 13:14