0

我想在表格中添加一个链接,用于下载和删除我上传的数据codeigniter。这是我的查看器,它只显示我上传的数据库中的文件名和日期

foreach($query as $row)
{
  echo "<tr>";
  echo "<td><h2>". $row->filename ."</h2></td>";
  echo "<td><h2>". $row->date ."</h2></td>";
  echo "<td><h2>".$row->filelink."</h2></td>";
  //now how can i make download and delete from my database
  //my database contains filename,fileid,filelink       
  echo "</tr>";
}

我的模型是

function showfile()
{
  $this->db->select('filename, filelink, date');
  $query = $this->db->get('upload_file');   
  return $query->result();
}

我的控制器

function index()
{
  $this->load->model('showuploadmodel');
  $data['query']=$this->showuploadmodel->showfile(); 
  $this->load->view('showupload_view',$data);
}

我想添加一个删除链接和下载链接,只从数据库中删除一个特定的行并下载一个传递了 Id 的文件。如何将数据库中的字段传递给下载助手?

4

1 回答 1

0

将字段传递给调用下载助手的控制器,而不是下载助手本身

尝试这个

 foreach($query as $row)
 {
    echo "<tr>";
    echo "<td><h2>". $row->filename ."</h2></td>";
    echo "<td><h2>". $row->date ."</h2></td>";
    echo "<td><h2>".$row->filelink."</h2></td>";
     echo "<td><h2><a href='".site_url('path/to/controllers/download/'.$row->id)."'>Download</a></h2></td>";
     echo "<td><h2><a href='".site_url('path/to/controllers/delete/'.$row->id)."'>Delete</a></h2></td>";
   echo "</tr>";
 }

并在控制器中添加相关功能

 function download($id){
       //$id is that particular Id 
      //do stuff with download helper
 }

 function delete($id){
       //$id is that particular Id 
       //delete code
 }
于 2013-07-10T08:13:21.033 回答