2014-10-01 57 views
2

我使用codeigniter日曆類,我試圖顯示當前月份的所有保留。在那一天的領域,我可能會有不止一個結果,我想讓他們分開昏迷。codeigniter日曆類錯誤消息

不過,我得到以下錯誤信息:顯示

A PHP Error was encountered 
Severity: Notice 
Message: Undefined property: stdClass::$reservationID 
Filename: models/reservationcalendarmodel.php 
Line Number: 81 

A PHP Error was encountered 
Severity: Notice 
Message: Undefined property: stdClass::$reservationArrivalDate 
Filename: models/reservationcalendarmodel.php 
Line Number: 81 

錯誤10次(我希望從數據庫9條)

這裏是從模型中(相關)代碼:

function getReservations($year,$month) { 
    $currentHotelUser = $this->session->userdata('currentHotelUser'); 
    $query = $this->db->query(
     "SELECT r.* 
     FROM room r 
     LEFT JOIN (SELECT rr.roomID, re.reservationID,re.reservationArrivalDate 
     FROM reservationroom rr 
     LEFT JOIN reservation re ON re.reservationID = rr.reservationID 
     WHERE re.reservationArrivalDate LIKE('".$year."-".$month."-%')) 
     sq ON sq.roomID = r.roomID 
     WHERE r.hotelID = ".$currentHotelUser['hotelID']." 
     AND sq.reservationID IS NOT NULL    
    "); 

    $cal_data = array(); 
    foreach($query->result() as $row) { 
     // BELLOW IS THE LINE 81 WHERE THE ERROR IS 
     $cal_data[substr($row->reservationArrivalDate,8,2)]= $row->reservationID; 
    } 
    return $cal_data; 
}  

function generate($year,$month) { 
    $cal_data = $this->getReservations($year, $month); 
    $this->load->library('calendar', $this->conf); 
    return $this->calendar->generate($year,$month,$cal_data);  
} 

這裏是來自控制器的(相關)碼:

$this->load->model('ReservationCalendarModel'); 
$data['calendar'] = $this->ReservationCalendarModel->generate($year,$month); 

下面是從視圖的(相關)代碼:

echo $calendar; 

沒有人知道爲什麼會出現上述錯誤?

+0

這可能會幫助你:http://stackoverflow.com/questions/3440839/codeigniter-model-error-undefined-property – Matheno 2014-10-01 13:28:35

+0

我有以下幾點:$自動加載['libraries'] = array('database','session'); – user2417624 2014-10-01 13:30:23

+0

在違規行前添加'print_r($ row)'。發佈結果。 – 2014-10-04 17:23:18

回答

2

問題是你的查詢結果沒有reservationID和reservationArrivalDate。這就是原因,在你循環的過程中出現這個錯誤。在主選擇查詢,添加這兩列

"SELECT r.*, sq.roomID, sq.reservationId 
     FROM room r 
     LEFT JOIN (SELECT rr.roomID, re.reservationID,re.reservationArrivalDate 
     FROM reservationroom rr 
     LEFT JOIN reservation re ON re.reservationID = rr.reservationID 
     WHERE re.reservationArrivalDate LIKE('".$year."-".$month."-%')) 
     sq ON sq.roomID = r.roomID 
     WHERE r.hotelID = ".$currentHotelUser['hotelID']." 
     AND sq.reservationID IS NOT NULL    
    "