在两个控制器中使用输入变量


Using input variable in two controllers

我在使用一个"输入变量"时遇到问题,但对于不同的控制器(和模型),我使用的是代码点火器。

我在view1中有一个表单,提交后我们调用controller1controller1验证$this->input->post(name)是否存在:

if exist {echo exist }
else {
// redirect to another controller2 when you should click "add" to add
// "$this->input->post(name)" to a table
}

现在我不知道如何在第二个model2中使用相同的变量$this->input->post(name)

如果你能帮助我,我将不胜感激。

您可以在控制器1:中执行类似操作

redirect('/Controller2/function2/value');

在你的控制器2中,类似这样的东西:

public function function2($value){
    // send value to the model
}

你也可以用会话来完成,但选择权在你的

您可以将其保存到变量中并将其传递给

例如

    //get the variable and save it
    $myVariable = $this->input->post('name');
    //load the model
    $this->load->model('model2');
    //now send the variable to the model 
    $this->model2->doSomethingElse($myVariable);