在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);
}
}
}
我第一次改變$ minPrice和$ maxPrice變量的結果是正確過濾,正是我需要的 但提高了$ maxPrice再次高價格不是添加到$ filteredResults
我也試着將$ offer和$ result賦值給新的變量,但仍然不工作 任何想法如何解決這個問題?
ps。我無法更改查詢或已經用查詢獲取它們。
您是否在更改屬性後_rewrite_會話中的實體? – Timurib
沒有重寫正在發生這是與此 –