我想在我的表格视图中显示两列,一列是文档的标题,另一列是文档的描述。我在特定的表中选择了一个名为“文件名”的列,该列存储与其标题和描述相关联的上载文档的名称。使用查询结果在HTML表格中生成链接。 (Codeigniter)
我很好奇我将如何设置包含在“文件名”列中的数据作为标题的超链接值时只显示标题和说明? (基本上,我希望他们能够下载一个文件,一旦他们点击它的名称)
我相当肯定,我可以通过跳过表生成器和做一个“foreach”以便打印出结果集中的所有数据,但我愿意接受这些建议,因为这会造成草率的代码。下面是我的控制器的一个片段。
<?php
class blah extends CI_Controller {
public function troubleshooting() {
$this->load->library('pagination');
$this->load->library('table');
$config['base_url'] = 'http://somewebsite.com/troubleshooting';
$config['total_rows'] = $this->db->get('document')->num_rows();
$config['per_page'] = 10;
$config['num_links'] = 10;
$this->pagination->initialize($config);
$data['records'] = $this->db->get('document', $config['per_page'],$this->uri->segment(3));
$this->db->select('doc_title, filename, description, category_id, product_id');
$this->db->where('category_id = 1');
$this->db->where('product_id = 1');
$this->db->order_by('doc_title', 'asc');
$this->load->view('blah/troubleshooting.php', $data);
}
}
请在模型中进行查询 –
我明白这是一种最佳做法,但我只是在此实例中构建了几个小静态页面。是否有任何特定的原因具体到我上面提到的目的,您建议我在模型中放置查询?如果是这样,你能否详细说明一下? – Elliott