2014-09-30 22 views
0

我在使用一个“输入变量”时出现问题,但在不同的控制器(和模型)中,我使用的是代码点火器。在两个控制器中使用输入变量

我有view1形式,提交一次我们称之为controller1,则controller1验证是否$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

重定向通过URL发送值并将其存入控制器2 – senK 2014-09-30 11:25:04

+1

或者您可以保存会话并可以在任何地方使用。 – 2014-09-30 11:26:28

回答

0

你可以做这样的事情在控制器1:

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

在你的控制器2是这样的:

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

您也可以与会议做,但选择权在你

0

您可以将其保存到一个变量中并通过它

例如

//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); 
相关问题