Phreeze Criteria的应用,在两个表里面查找多个符合条件的数据
public function GetDataJson(){ $cv_id=$this->getRouter()->GetUrlParam('cvId'); $ds=$this->GetSets($cv_id); echo '<pre>'; print_r($ds); $data_json=json_encode($ds); 将结果集转化为json, echo $data_json; } /* * 返回查找结果的数据集,并且拼凑出自己想要的形式。
返回结果类型:
Array ( [11] => Array ( [cr_id] => 1 [v_id] => 1 [v_name] => 我爱我家 [v_link] => http://2 [is_part] => 0 [duration] => 5630 [begin_time] => Array ( [1] => 2356666 [22] => 523642 ) ) [12] => Array ( [cr_id] => 1 [v_id] => 2 [v_name] => 我爱我家 [v_link] => http://3 [is_part] => 0 [duration] => 5638 [begin_time] => Array ( [23] => 1256 ) ) )
*/ protected function GeSets($cv_id) { include_once 'Model/ZjCarouselVideo.php'; include_once 'Model/ZjlCarouselEpg.php'; $criteria_carousel_video = new ZjCarouselVideoCriteria(); $criteria_carousel_epg = new ZjCarouselEpgCriteria(); $criteria_carousel_video->cr_id_Equals =$cv_id; $carousel_video = $this->Phreezer->Query("ZjCarouselVideo",$criteria_carousel_video); $carousel_video = $carousel_video->ToObjectArray(true,$this->SimpleObjectParams()); foreach($carousel_video as $key => $val){ foreach($val as $k =>$v){ if ($k=='id') continue; $re_cv[$val->id][$k]=$v; } } foreach($re_cv as $key => $val){ $criteria_carousel_epg->cr_id_Equals=$val['cr_id']; $criteria_carousel_epg->v_id_Equals=$val['v_id']; $carousel_video_epg=$this->Phreezer->Query('ZjCarouselEpg',$criteria_carousel_epg); $carousel_video_epg=$carousel_video_epg->ToObjectArray(true,$this->SimpleObjectParams()); $i=0; foreach ($carousel_video_epg as $key => $val){ $epg_info['cr_id']=$val->cr_id; $epg_info['v_id']=$val->v_id; $epg_info[$i]['cr_epg_id']=$val->cr_epg_id; $epg_info[$i]['begin_time']=$val->begin_time; $i++; } $cr_epg[]=$epg_info; $criteria_carousel_epg=new ZjCarouselEpgCriteria(); $epg_info=array(); } foreach ($re_cv as $k_video => $v_video){ foreach ($cr_epg as $k_epg=>$v_epg){ if($v_epg['cr_id']==$v_video['cr_id']&&$v_epg['v_id']==$v_video['v_id']){ array_shift($v_epg); array_shift($v_epg); foreach ($v_epg as $v_k=>$v_info){ $v_video['begin_time'][$v_info['cr_epg_id']]=$v_info['begin_time']; } } $re_cv[$k_video]=$v_video; } } return $re_cv; }