[英]Saving multiple image paths while inserting data in 2 tables in Codeigniter
I am trying to make this app work. 我正在尝试使此应用正常工作。 At the moment it does upload multiple images to '[upload]' folder and data in one of the table (other than image folder).
目前,它确实将多个图像上传到“ [upload]”文件夹,并将数据上传到表之一(而不是图像文件夹)中。
I have 2 tables. 我有2张桌子。 One for other info and one images only.
一个用于其他信息,仅一个图像。 Other info table inserts even if there is an error.
即使有错误,也会插入其他信息表。 while image table doesn't insert anything.
而图像表不插入任何内容。
My model is: 我的模型是:
function insert_property_details($data) {
$this->db->trans_start();
// First Table
$insert_property_in_database=array(
'v_item_title' => $this->input->post('v_item_title'),
'v_item_description' => $this->input->post('v_item_description'),
'images_reference_id' => $this->db->insert_id(),
);
$query=$this->db->insert('vbc_vacation_item_attri',$insert_property_in_database);
return $query;
// Second Table
$data = array('property_images' => $data['uploadedimage']);
$this->db->insert('vbc_property_images', $data);
$this->db->trans_complete();
return $this->db->insert_id();
}
Upload controller: 上传控制器:
$this->upload->initialize($config);
if ($this->upload->do_upload('uploadedimage')) {
$data['upload_data'] = $this->upload->data();
$image_name = $data['upload_data']['file_name'];
$data['upload_data'] = $image_name;
$this->load->model('admin/model_users');
$this->model_users->insert_property_details($data);
} else {
Controller that links to FORM: 链接到FORM的控制器:
public function post_property() {
//Some validation code here
if($this->form_validation->run() == FALSE) {
redirect('dashboard/add-new-listing');
} else {
$this->load->model('admin/model_users');
if($query = $this->model_users->insert_property_details()) {
redirect('dashboard/property-successfully-posted');
}
}
And the FORM: 和表格:
<input type="file" class="input-text-custom" data-placeholder="select image/s" name="uploadedimages[]" accept="image/*" multiple id="file" />
Please Help. 请帮忙。
In your model there is a return
statement given - 在您的模型中,给出了一个
return
语句-
return $query;
So the remaining codes won't execute, that's why images related data is not inserting 因此,其余代码将不会执行,这就是为什么图像相关数据未插入的原因
function insert_property_details($data) {
$this->db->trans_start();
// First Table
$insert_property_in_database=array(
'v_item_title' => $this->input->post('v_item_title'),
'v_item_description' => $this->input->post('v_item_description'),
'images_reference_id' => $this->db->insert_id(),
);
$query=$this->db->insert('vbc_vacation_item_attri',$insert_property_in_database);
// return $query; this is not required
// Second Table
$data = array('property_images' => $data['uploadedimage']);
$this->db->insert('vbc_property_images', $data);
$this->db->trans_complete();
return $this->db->insert_id();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.