dongyishe6689 2015-12-30 21:45
浏览 48

Codeigniter-session值并将参数传递给controller方法

I'm using Codeigniter 3 framework and encounter a problem.
In my app, there is 2 controller:
Main and User.
In Main controller, there are two methods, method1 (with no parameter) and method2 (with one parameter), which both load own view, but there is an identical form in their view that will be submitted to User controller method. In both method1 and method2, I generate a random number and store in $data['random'], also in a session variable (for future checking):
$data['random'] = generate_random();
$this->session->set_userdata('random', $data['random']);
$data['random'] in both method is set in form input and then submitted.
The problem is: when I retrieve data (in User controller) which is submitted from method1, and compare with session value, they are equal. BUT this scenario for method2 is different. the submitted value is not equal to session value!!!
The only difference between methods is: method2 accept parameters and method1, no.
NOTE: when I assign a fixed number (instead of generate random) to $data['random'], the result of both methods are equal.

Edited: added codes

The Main controller methods:

public function method1(){
 //other data setting and...

 $data['random'] = generate_random();
 $this->session->set_userdata('random', $data['random']);

 $this->load->view('view_folder/first', $data);
}

public function method2($param){
 //other data setting and...

 $data['random'] = generate_random();
 $this->session->set_userdata('random', $data['random']);

 $this->load->view('view_folder/second', $data);
}

The User controller method:

public function check(){
 echo $this->input->post() . '<br>';
 echo $this->session->userdata('random');
 exit();
 //other...
}


In view files, an identical form is part of view code. As I said, $data['random'] will be set as input value in form and this will be submitted. Another thing, in first view file, there some items which link to method2:

<!-- other -->
<a href="<?php echo base_url();?>main/method2/3">some item</a>
<a href="<?php echo base_url();?>main/method2/some_var">some item</a>
<!-- other -->


I check code carefully, test different cases, I think this problem related to passed argument to method2. I mean, the passed parameter create problem. But I have no idea and logical reason!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 划分vlan后不通了
    • ¥15 GDI处理通道视频时总是带有白色锯齿
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制
    • ¥15 merge函数占用内存过大
    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大