我得到第一个var_dump的期望值,但是在提交表单时var_dump都得到一个空值。任何人都可以帮我这个吗? 确切地说,当表单未提交时,我能够获得get-> trail-> id的所需结果,但是一旦我完成表单并提交它,$ id的值被指定为null
public function trail_cat_cost($trail_unique_code = null)
{
if($this->userlib->isLoggedIn())
{
$code = $trail_unique_code;
$user_id = $this->userlib->getId();
$id = $this->seller_store_model->get_trail_id($code, $user_id);
var_dump($id);
$choice = $this->input->post("travel_cat");
if(is_null($choice))
{
$choice = array();
}
$travel_cat = implode(',', $choice);
$choice1 = $this->input->post("travel_subcat");
if(is_null($choice1))
{
$choice1 = array();
}
$travel_subcat = implode(',', $choice1);
$trail_currency = $this->input->post('trail_currency');
$trail_cost = $this->input->post('trail_cost');
$cost_valid_from = $this->input->post('cost_valid_from');
$cost_valid_upto = $this->input->post('cost_valid_upto');
//$this->form_validation->set_rules('travel_cat', 'Travel Category', 'trim|required');
//$this->form_validation->set_rules('travel_subcat', 'Travel Subcategory', 'trim|required');
$this->form_validation->set_rules('trail_currency', 'Trail Currency', 'trim|required');
$this->form_validation->set_rules('trail_cost', 'Trail Cost', 'trim|required');
$this->form_validation->set_rules('cost_valid_from', 'Cost Valid From', 'trim|required');
$this->form_validation->set_rules('cost_valid_upto', 'Cost Valid Upto', 'trim|required');
if($this->form_validation->run() == FALSE)
{
$this->load->view('trail_cat_cost');
}
else
{
var_dump($id);
$this->seller_store_model->trail_cat_cost($user_id, $id, $travel_cat, $travel_subcat, $trail_currency, $trail_cost, $cost_valid_from, $cost_valid_upto);
echo "success";
//redirect('/seller_store/trail_overview/'.$date);
}
}
else
{
echo "User not authorised";
}
}
评论中的模型代码
public function get_trail_id($code, $user_id) {
$query = $this->db->query("SELECT id FROM trail_basic_info WHERE trail_unique_code = '$code' AND user_id = '$user_id'"); foreach($query->result() as $row) { $id = $row->id; $data = array('trail_id'=>$id); $this->db->update($this->search, $data, array('trail_unique_code'=>$code, 'user_id'=>$user_id)); return $row->id;
}