symfony와 Doctrine에서 세션을 사용하여 쿼리 결과를 저장하고 나중에 일부 매개 변수로이 결과를 필터링합니다. 문제는 일단 매개 변수가 변경되면 원래 결과 집합을 가져올 수 없다는 것입니다. 여기서 코드내 세션 데이터가 변경되는 이유는 무엇입니까?
페칭 결과는 결과
필터링 다른 함수에서 세션 후
$query = $this->getDoctrine()->getManager()->createQueryBuilder();
$query->select("sp")
->from("CoreBundle:ServiceProvider","sp")
->innerJoin("sp.offers","offer")
->innerJoin("offer.service","service","with","offer.service = service")
->innerJoin("sp.firstImage","fi")
->andWhere("sp.city = :city_name")->setParameter("city_name",$cityName)
->orderBy("sp.points" ,"DESC")
->addOrderBy("sp.name" ,"ASC");
$queryAndFilters = $this->getFilters($query,$postData);
$query = $queryAndFilters['query'];
$filters=$queryAndFilters['filters'];
$paginator = $this->get('knp_paginator');
$pagination = $paginator->paginate(
$query, /* query NOT result */
$pageNumber,
20/*limit per page*/
);
$query = $query->getQuery();
$query->setHint(\Doctrine\ORM\Query::HINT_INCLUDE_META_COLUMNS, true);
$this->get('session')->set("results",$query->getResult());
및 저장
$results = $this->get('session')->get("results");
$filteredResults = array();
// print_r(array_keys($results[0]));
foreach($results as $result){
$sp = $result;
foreach($sp->getOffers() as $offer){
// echo "found offer ".$offer->getName()." with price ".$offer->getPrice()."<br />";
$sp->removeOffer($offer);
if($offer->getPrice() < $minPrice || $offer->getPrice() > $maxPrice){
}else{
$sp->addOffer($offer);
// echo 'added $offer '.$offer->getName()." with price : ".$offer->getPrice()."<br />";
}
if(sizeof($sp->getOffers()) > 0){
array_push($filteredResults,$sp);
}
}
}
처음 나는 변경 $ 최소 가격 및 $ maxPrice 변수 결과가 정확하게 필터링되고 이 필요하지만 $ maxPrice를 높이면 다시 가격이 높지 않습니다. $ filteredResults에 추가했습니다.
나는 새로운 변수에 $ offer와 $ result를 할당하려고했지만 여전히 작동하지 않습니다. 어떻게 해결할 수 있습니까?
ps. 나는 질의를 변경하거나 질의로 이미 가져올 수 없다.
세션의 엔티티가 속성을 변경 한 후에 그 엔티티를 쓰지 않습니까? – Timurib
재 작성이 일어나지 않습니다.이 코드와 관련된 전체 코드는 –