|
下面模型中的插入代码,可以上传文件, 表名:picture 表里有3个字段:workid(ID)、path(图片保存路径)、mark(view视图中的名字,也就是下面那四个)
view视图中上传文件的名字分别是:<input name="before_front_img" />
before_side_img、later_front_img、later_side_img 命名为这四个。
下面是模型中插入表里的代码:
public function add_work_pic($uid, $pic)
{
$data = array();
$row = array();
if ($row = $this->db->where(array('uid' => $uid))->get($this->table)->row_array()) {
#直接在图片表里添加
$work_id = $row['id'];
} else {
#先添加work表,再添加图片表
$this->db->insert($this->table, array('uid' => $uid));
$work_id = $this->db->insert_id();
}
if ($pic['before_front_img']) {
$this->db->delete('picture', array('mark' => 'before_front_img', 'workid' => $work_id));
$data[0]['workid'] = $work_id;
$data[0]['path'] = $pic['before_front_img'];
$data[0]['mark'] = 'before_front_img';
}
if ($pic['before_side_img']) {
$this->db->delete('picture', array('mark' => 'before_side_img', 'workid' => $work_id));
$data[1]['workid'] = $work_id;
$data[1]['path'] = $pic['before_side_img'];
$data[1]['mark'] = 'before_side_img';
}
if ($pic['later_front_img']) {
$this->db->delete('picture', array('mark' => 'later_front_img', 'workid' => $work_id));
$data[2]['workid'] = $work_id;
$data[2]['path'] = $pic['later_front_img'];
$data[2]['mark'] = 'later_front_img';
}
if ($pic['later_side_img']) {
$this->db->delete('picture', array('mark' => 'later_side_img', 'workid' => $work_id));
$data[3]['workid'] = $work_id;
$data[3]['path'] = $pic['later_side_img'];
$data[3]['mark'] = 'later_side_img';
}
return $this->db->insert_batch('picture', $data);
}
下面这两个方法是模型中的查询出数据的方法
public function update_work($uid, $data)
{
return
($row = $this->db->where(array('uid' => $uid))->get($this->table)->row_array()) && $this->db->where(array('id' => $row['id']))->update($this->table, $data);
}
public function get_work($id)
{
return $this->db->where(array('id' => $id))->get($this->table)->row_array();
}
我怎么得到这个$data[3]['path'] 数组中的路径,调出让它显示出来, 控制器怎么写,视图里怎么写?大神来看看
|
|