在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
没有重写正在发生这是与此 –