在cakephp3中,我似乎无法在查询结果中添加一个字段。在cakephp2中,这个想法很简单但是因为我处理的是对象,所以这是不同的。我检查过以前的SE帖子,但无法得到答案。它必须简单,但我无法找到它。 在这里,我尝试将自定义字段“距离”添加到结果集
$lessons=$this->Lessons->getLessonsDay($searchDate,$searchFirstName,$searchLastName,$searchSubject, $tutorIds);
foreach( $lessons as $key => $item){
// debug($item);
$stlat=$item->student->address_lat;
$stlong=$item->student->address_long;
$tutlat=$item->tutor->address_lat;
$tutlong=$item->tutor->address_long;
$dist=$this->calculate_distance( $stlat,$stlong,$tutlat,$tutlong);
debug($dist);
$lessons->distance= $dist; //no effect
$lessons[$key]['distance']=$dist; //error
$lessons[$key]['Lessons']['distance']=$dist; //Error: Cannot use object of type Cake\ORM\Query as array
}
答案 0 :(得分:-1)
也许你想做
$item->distance = $dist – arilia