2011-01-25 38 views
2

訪問數據我有這樣從形式陣列笨

<form> 
<input type="text" name="personal_details[]" /> 
<input type="text" name="personal_details[]" /> 

<input type="text" name="pictures[]" /> 
<input type="text" name="pictures[]" /> 
</form> 

用PHP,我可以這樣

$name = $_POST['personal_details'][0]; 
$surname = $_POST['personal_details'][1]; 
etc.. etc 

訪問的數據是否有可能做笨輸入類此任務的形式?

回答

2

他們的工作基本相同。

$personal_details = $this->input->post('personal_details'); 
$pictures = $this->input->post('pictures'); 

$name = $personal_details[0]; 
$surname = $personal_details[1]; 
+0

我只是想知道如果有另一種方式。 類似於$ this-> input-> post('var',[0,1,2等]); 關於用戶指南,沒有這樣的方式來獲取數據 – Dro1n2

+0

http://codeigniter.com/user_guide/libraries/input.html。 CI有一些*最好的文檔,你會發現 – Ross

0

下面的表格,取自上面的示例以及一些附加內容。

<form> 
<input type="text" name="personal_details[]" /> 
<input type="text" name="personal_details[]" /> 

<input type="text" name="pictures[]" /> 
<input type="text" name="pictures[]" /> 

<input type="text" name="details[first_name]" /> 
<input type="text" name="details[last_name]" /> 
</form> 

這可以在您的控制器或模型中使用,如下所示。

echo $this->input->post('personal_details')[ 0 ]; 
echo $this->input->post('personal_details')[ 1 ]; 
echo $this->input->post('pictures')[ 0 ]; 
echo $this->input->post('pictures')[ 1 ]; 

echo $this->input->post('details')[ 'first_name' ]; 
echo $this->input->post('details')[ 'last_name' ]; 

我希望這會有所幫助。我想知道同樣的事情並試驗,直到找到這個解決方案。