简体   繁体   English

Codeigniter:将post变量从一个函数传递到控制器中的另一个函数

[英]Codeigniter: passing a post variable from one function to another in a controller

Am getting a variable called $msisdn from a view using post in one function (search_results). 我在一个函数中使用post(search_results)从一个视图中获取了一个名为$ msisdn的变量。 After doing the processing, I would like to use the same variable in another function(assign_role) currently,I am unable to do that since am getting this error 完成处理后,我现在想在另一个函数(assign_role)中使用相同的变量,由于出现此错误,我无法执行此操作

Severity: Notice Message: Undefined variable: msisdn 严重性:通知消息:未定义的变量:msisdn

. Below is my search_result function where am getting the post data: 以下是我的search_result函数,该函数在其中获取发布数据:

public function search_results(){

    $msisdn =  $this->input->post('search_data');//getting data from the view


    if ($msisdn == false){

        $this->load->view('add_publisher');

    } else{
        $this->assign_role($msisdn); //passing the variable to another function

        $this->load->model('search_model');


        $data['result'] = $this->search_model->search_user($msisdn);
        $data1['box'] = $this->search_model->search_select($msisdn);

        $result = array_merge($data, $data1);  

        $this->load->view('add_publisher',$result);

        echo json_encode($result);
    }

} 

I want to use $msisdn from above function in this function below: 我想在以下功能中使用上述功能中的$ msisdn:

public function assign_role($msisdn){

    //echo $msisdn['numm'];

    $publisher = $this->input->post('select');

    if ($publisher == false) {

        $this->load->view('add_publisher');

    } else {

        $data = array(
           'publisher' => true,
        );

        $this->load->model('insert_model');

        $data1 = $this->insert_model->search_group($msisdn, $data);             

            if ($data1 == true) {

                echo "Recorded updated succesfully";
                $this->load->view('add_publisher');

            } else {

                echo "Recorded not updated";
                $this->load->view('add_publisher');

            }

    }

}

Please help me to achieve this. 请帮助我实现这一目标。

Passing variables from one function to another in the same controller can be achieved by using sessions. 通过使用会话,可以将变量从一个功能传递到同一控制器中的另一个功能。 In Codeigniter, one can use flashdata like: 在Codeigniter中,可以使用flashdata,例如:

$this->session->set_flashdata('info', $MyVariable);

Remember, flashdata is only available for the next server request then it will be automatically cleared. 请记住,闪存数据仅可用于下一个服务器请求,然后它将自动清除。 Then it can be retrieved as: 然后可以将其检索为:

$var = $this->session->flashdata('info');

If you want to keep the variable for one more server request, you can do this: 如果要为另一个服务器请求保留该变量,则可以执行以下操作:

$this->session->keep_flashdata('info');

Hope this will help someone faced with the problem. 希望这可以帮助遇到问题的人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Codeigniter中将uri分段变量从一个函数传递给另一个函数 - Passing uri segment variable from one function to another in Codeigniter 将变量从一个函数传递到同一控制器中的另一个函数 - Passing variable from one function to another function in same controller 将变量从一个函数传递到同一控制器中的另一个函数(laravel 5) - Passing variable from one function to another function in same controller (laravel 5) Codeigniter从一个类中的另一个函数获取变量(具有后置值) - Codeigniter get variable (with post value) from another function in one class 将变量从一个Controller Action传递给另一个 - Passing a variable from one Controller Action to another 将变量从一种控制器方法传递到另一种方法 - Passing a variable from one controller method to another 将变量从一个函数传递到另一个函数 - Passing variable from one function to another function 将变量值从一个控制器传递到另一个控制器 laravel - Passing variable value from one controller to another controller laravel 如何使用Codeigniter将变量从函数发送到同一控制器中的另一个函数 - how to send variable from function to another function in a same controller with codeigniter 将变量值从一个函数传递到另一个函数 - Passing variable value from one function to another
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM