2014-09-30 29 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); 
相關問題