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 安卓adb backup备份应用数据失败
    • ¥15 eclipse运行项目时遇到的问题
    • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
    • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
    • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
    • ¥50 成都蓉城足球俱乐部小程序抢票
    • ¥15 yolov7训练自己的数据集
    • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
    • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
    • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)