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
これは何も書かれていません。これは、 –