2011-06-26 44 views
0

我使用笨1.7.1.Ok這裏是有史以來表單提交的scenario.When,我需要做兩件事情重定向和set_select問題

1)堅持在下拉列表中選擇的值。 2)使用session->set_flashdata(),我需要設置自定義數據庫消息。

現在,我們知道,我們需要重定向之前,這個閃存數據可以設置。

這是我寫的代碼。

if ($this->form_validation->run() == TRUE){ 

    $this->session->set_flashdata(‘msg’, ‘Taha Hasan’); 
    redirect(current_url()); 

    $this->ShowReceiveInventoryView(); 
} 

另外我在下拉視圖中使用set_select來保存該值。

<select name=「myselect」> 
<option value=「one」 <?php echo set_select(‘myselect’, ‘one’, TRUE); ?> >One</option> 
<option value=「two」 <?php echo set_select(‘myselect’, ‘two’); ?> >Two</option> 
<option value=「three」 <?php echo set_select(‘myselect’, ‘three’); ?> >Three</option> 
</select> 

現在,這裏是......而是因爲我重定向到當前頁面顯示提示信息的問題,下拉set_select值丟失!默認值出現在選擇:(..如果我刪除代碼中的重定向線,下拉值是presisted但閃存數據沒有設置!!!

希望你們有這個問題的解決方案...

回答

1

set_select()只有當$_POST陣列包含內容(如你發現),但您的重定向顯然是一個GET請求工作。

來處理這個正確的方法是在控制器內執行查詢,傳遞對象將在您的視圖中進行編輯,然後在您的視圖中重新填充表格或設置默認值,根據$_POST(如果存在或基於傳遞的對象)噸。

我們假設我們正在編輯一個產品,它有myselect(一個可怕的命名的字段)屬性。我們將使用PHP的三元運算符來測試產品的參數myselect的值是否等於當前的option - 如果是,我們將使用set_selects()的第三個參數來設置默認值。

<option value="one" <?php echo set_select('myslect', 'one', ((!$product) || !$this->input->post('myselect') && $product->myselect == 'one' ? TRUE : FALSE); ?>One</option> 

<option value="two" <?php echo set_select('myselect', 'two', (!$this->input->post('myselect') && $product->myselect == 'two' ? TRUE : FALSE); ?>Two</option> 
+0

感謝您的幫助先生。 – Taha