0
我不知道我的CakePHP應用程序究竟發生了什麼。它在上週工作,我沒有改變那個特定的文件。在CakePHP中查找所有在我的視圖中傾倒分號
當我在我的控制器中使用find'all'時,即使視圖文件中沒有任何內容,它也會在我的視圖中轉儲一個分號。
這裏是我的代碼
$evts = $this->Event->find('all');
沒有什麼在我的視圖文件。我不知道它是否有所作爲,但我使用的是json視圖。
如這裏要求是針對行動
public function search(){
$this->Event->recursive = 2;
$conditions = array();
if(!empty($this->request->query['name'])){
$conditions = array('Event.name LIKE ' => "%" . str_replace(" ","%", $this->request->query['name']) . "%");
}
if(!empty($this->request->query['home'])){
$conditions = array('Event.home_team_id' => $this->request->query['home']);
}
if(!empty($this->request->query['away'])){
$conditions = array('Event.away_team_id' => $this->request->query['away']);
}
$limit = 25;
if(!empty($this->request->query['limit'])){
$limit = $this->request->query['limit'];
}
//$evts = $this->Event->find('all',array('conditions'=>array($conditions),'order' => array('Event.start_time'),'limit'=>$limit));
$evts = $this->Event->find('all');
$this->set('events',$evts);
}
視圖中的一切已被註釋掉的完整代碼...但這裏是代碼反正
$results = array();
$i = 0;
foreach ($events as $event) {
$results[$i]['id'] = $event['Event']['id'];
$results[$i]['label'] = $event['Event']['name'] . "(" . date_format(date_create($event['Event']['start_time']), 'D, jS M Y') . ")";
$results[$i]['value'] = $event['Event']['name'];
$results[$i]['home_team_name'] = $event['HomeTeam']['name'];
$results[$i]['away_team_name'] = $event['AwayTeam']['name'];
$results[$i]['sport_name'] = $event['Sport']['name'];
$results[$i]['tournament_name'] = $event['Tournament']['name'];
$results[$i]['start_time'] = $event['Event']['start_time'];
$results[$i]['img'] = $event['Event']['img_path'];
$results[$i]['listener_count'] = 0; //TODO Get the follower count
$i++;
}
echo json_encode($results);
顯示
請添加完整的動作代碼,其中包含此代碼 –
@MoyedAnsari我已添加完整代碼 – TemiGiwa
search.ctp中沒有任何內容?請在操作中調試$ evts。 –