簡體   English   中英

在codeigniter中顯示用於表單編輯的數據和圖像

[英]Showing Data and Image for Form Edit in codeigniter

我的汽車模型具有可編輯的形式,用戶可以編輯和刪除汽車。 當用戶單擊編輯時,他們可以在編輯表單上看到汽車,型號,年份,價格,並進行新的更改並提交。 我也要顯示和編輯上傳的圖像。 我知道form_input()不會顯示圖像。 我嘗試了所有操作,但不會顯示在我的編輯表單中。 這是我的代碼,謝謝!

controller:
public function input($id = 0) {

$this->load->helper('form');  
$this->load->helper('html');    
$this->load->model('model_users');

/*
if($this->input->post('submit')) {
    $this->model_users->entry_insert();
}
$data = $this->books_model->general();
*/

   if((int)$id > 0) {
     $query = $this->model_users->get($id);
  $data['fid']['value'] = $query['id'];
  $data['fcar_make']['value'] = $query['car_make'];
  $data['fcar_model']['value'] = $query['car_model'];
  $data['fcar_year']['value'] = $query['car_year'];
  $data['fcar_lease']['value'] = $query['car_lease'];
  $data['fcar_payment']['value'] = $query['car_payment'];
  $data['fimgpath']['value'] = $query['imgpath'];

}


if($this->session->userdata('is_logged_in')) {          
$this->load->view('edit_car',$data);    
}

else {
redirect('main/restricted');
}


 }


Model:

function get($id) {

        $this->db->where(array('id'=>$id));
        $query = $this->db->get('cars');
        return $query->row_array();
    }


view

<tr>
  <td>Car Lease:</td>
  <td><input type="text" class="textbox" tabindex="6" name = "<?php echo form_input($fcar_lease); ?></td>
  <td>&nbsp;</td>

</tr>
<tr>
  <td>Car Payment:</td>
  <td><input type="text" class="textbox" tabindex="6" name = "<?php echo form_input($fcar_payment); ?></td>
  <td>&nbsp;</td>

</tr>

<tr>
  <td>Car Image:</td>
  <td><input type="file" name=""<?php echo form_input($fimgpath); ?>" size="20" /></td>
  <td>&nbsp;</td>

</tr>

您不能在文件上傳字段中顯示圖像或圖像路徑,而只能在文件上傳字段下方顯示圖像(就像您在前端顯示它一樣),並且如果用戶重新上傳圖像,請刪除現有的圖像,然后上傳新的,並更新數據庫中的映像名稱。

另外,您可以提供一個刪除按鈕以刪除同一界面上的圖像(可能在當前圖像下方)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM