我有一个向mysql数据库添加记录的方法。应用程序在codeignite中编程实现。我用以下代码获取当前登录用户的id-
$agentId = $this->session->userdata('agentid');
当我将$agentid回显到表单页的顶部时,它显示28,这是正确的。当单击save按钮并运行该方法时,会话将清除它并注销用户。我不明白为什么会这样。
public function add(){
$agentId = $this->session->userdata('agentId');
echo $agentId;
if(!$agentId){
redirect(base_url().'login', 'refresh');
}
if(!isSuperAdmin() && !isPayment()){
redirect(base_url().'payment', 'refresh');
}
$data['p_title'] = $this->project_model->projectName().' :: Property : Add New Property';
$data['Message'] = '';
$data['heading'] = 'Property: Add New Property';
$data['pageName'] = 'property';
$data['title'] = filter_value('title', '');
$data['meta_decription'] = filter_value('meta_decription', '');
$data['keywords'] = filter_value('keywords', '');
$data['type'] = filter_value('type', '');
$data['sub_type'] = filter_value('sub_type', '');
$data['sub_type1'] = filter_value('sub_type1', '');
$data['bedrooms'] = filter_value('bedrooms', '');
$data['kitchen'] = filter_value('kitchen', '');
$data['parking'] = filter_value('parking', 'YES');
$data['bathrooms'] = filter_value('bathrooms', '');
$data['price'] = filter_value('price', '0.00');
$data['rent_frequency'] = filter_value('rent_frequency', '');
$data['deposit'] = filter_value('deposit', '0.00');
$data['location'] = filter_value('location', '');
$data['city'] = filter_value('city', 82);
$data['country'] = filter_value('country', 102);
$data['details'] = filter_value('details', '');
$data['featured'] = filter_value('featured', 'NO');
$data['countries'] = $this->general_model->listCountries($data['country']);
$data['cities'] = $this->general_model->listCities($data['country'], $data['city']);
$this->form_validation->set_rules('title', 'Property title', 'trim|required');
if($this->form_validation->run() === TRUE){
// the agentId variable is lost here, so 0 gets etntered in to the database and the user is logged out.
$agentId = $this->session->userdata('agentId');
$Date = getCurrentDate();
$Time = getCurrentTime();
$DbFieldsAry = array('agentId', 'title', 'meta_decription', 'keywords', 'type', 'sub_type', 'sub_type1', 'bedrooms', 'kitchen', 'parking', 'bathrooms', 'price', 'rent_frequency', 'deposit', 'location', 'city', 'country', 'details', 'featured', 'date');
$InfoAry = array($agentId, $data['title'], $data['meta_decription'], $data['keywords'], $data['type'], $data['sub_type'], $data['sub_type1'], $data['bedrooms'], $data['kitchen'], $data['parking'], $data['bathrooms'], $data['price'], $data['rent_frequency'], $data['deposit'], $data['location'], $data['city'], $data['country'], $data['details'], $data['featured'], $Date);
if($this->general_model->duplicateEntry($DbFieldsAry, $InfoAry, 'tbl_properties_list')){
$activityId = $this->general_model->getSingleValue($data['title'], 'title', 'property_id', 'tbl_properties_list');
setMessage('success_message', 'New property added successfully. Add pictures to property.');
redirect(base_url().'property/update/'.$activityId.'/0', 'refresh');
}
else{
setMessage('error_message', 'Unable to perofrm this operation, please try again later!');
redirect(base_url().'property/user_listing', 'refresh');
}
}
$data['allowed'] = true;
$data['warning'] = '';
if(!isSuperAdmin()){
$total_properties = $this->general_model->getTotalDataSimple1('property_id','tbl_properties_list');
if(allowed_properties() <= $total_properties){
$data['allowed'] = false;
$data['warning'] = '<br/>You have reached to maximum limit of your property upload listing.<br/>Click <a href="'.base_url().'payment">HERE</a> to change payment plan.<br/><br/><br/><br/><br/>';
}
}
$this->load->view('add_property', $data);
}
下面是config.php中的会话
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 14400;
$config['sess_expire_on_close'] = TRUE;
$config['sess_encrypt_cookie'] = FALSE;
$config['sess_use_database'] = FALSE;
$config['sess_table_name'] = 'ci_sessions';
$config['sess_match_ip'] = TRUE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update'] = 600;
1条答案
按热度按时间velaa5lx1#
我假设您已经在构造函数或自动加载文件中加载了会话库。如果不是,那可能就是问题所在。如果是,请尝试更改codeigniter的config.php中的会话超时或会话存储方法。