**答:我需要「反序列化」我的會話變量,然後才能使用。啊。Codeigniter會話值不堅持
$ eventTypeID = unserialize($ this-> session-> userdata('eventtypeID'));
我意識到這是一個痛打一頓的話題,但作爲新CI,我讀過通大部分文檔的,但是當涉及到正確設置/獲取會話我必須忽視的東西。
我已經按照在這篇文章中找到的配置,並確認FF被存儲的cookie:http://codeigniter.com/forums/viewthread/178904/
我的應用程序設置的方式,從2個下拉菜單可以通過選擇值,這些值然後投入會話變量和新視圖被調用。從新視圖中,我需要能夠訪問會話變量並傳遞它們以查詢我的數據庫。就目前來看,當我查看查詢時,沒有會話值被髮送給它。
非常感謝所有幫助!謝謝!
EDITED BELOW:似乎沒有發生會話變量(數組)的設置。
這裏是我的設置代碼:
public function goSearch(){
if(!empty($_POST)) {
$this->load->library('session');
$searchData = array(
'eventtypeID' => serialize($this->input->post('pEventType')),
'venuecityID' => serialize($this->input->post('pVenueCity'))
);
$this->session->set_userdata($searchData); /*ERROR: Nothing is being set. I've done print_r on $searchData, which returns values, but if I do:
$test = $this->session->set_userdata($searchData);
Print_r($test);
Nothing is returned */
$this->_displayPublicPage('search', NULL);
}
}
這裏是我用於獲取傳遞給查詢功能:
public function readEvents(){
$eventTypeID = $this->session->userdata(‘eventtypeID’);
$venueCityID = $this->session->userdata(‘venuecityID’);
echo json_encode($this->event_model->getSearchEvents($eventTypeID, $venueCityID));
}
這是我在我的模型查詢:
public function getSearchEvents($eventTypeID, $venueCityID){
$eventTypeID = intval($eventTypeID);
$venueCityID = intval($venueCityID);
$this->db->select('*');
$this->db->where('event_status =', 'A');
$this->db->where('eventtype.eventtype_id =', $eventTypeID);
$this->db->where('city.city_id =', $venueCityID);
$this->db->join('eventtype', 'event.fk_eventtype_id = eventtype.eventtype_id');
$this->db->join('venue', 'event.fk_venue_id = venue.venue_id');
$this->db->join('city', 'venue.fk_city_id = city.city_id');
$this->db->join('tickets', 'event.event_id = tickets.fk_event_id');
$this->db->from('event');
$this->db->_compile_select();
$q = $this->db->get();
echo $this->db->last_query();
if($q->num_rows() > 0) {
return $q->result();
} else {
return array();
}
}
你加載了你的會話類嗎? – 2011-07-29 16:57:53
是的。在autoload – user464180