这是循环函数:
public function download_contents($id) {
$the_contents = $this->db->get_where('contents', array('request_id' => $id));
$count = 1;
foreach ($the_contents->result() as $y) {
$file_name = $y->file_name;
$download_path = base_url('assets/client/contents/'.$file_name);
return '<p>' .$count++. '. ' .$file_name. '
<a class="btn btn-primary btn-xs" href="' .$download_path. '" title="Download Content">Download</a></p>';
}
}
现在我想在下面的函数中回显上述函数的结果:
public function modal_content_download($id) {
$y = $this->db->get_where('website_requests', array('id' => $id))->row();
$the_contents = $this->db->get_where('contents', array('request_id' => $id));
if ( $the_contents->num_rows() > 0 ) {
return '<button class="btn btn-primary btn-sm modal-toggle-btn" data-toggle="modal" data-target="#contents' .$id. '" title="Download Contents"> <i class="fa fa-download"></i></button>
<div class="modal fade" id="contents' .$id. '" role="dialog">
<div class="modal-dialog">
<div class="modal-content modal-width">
<div class="modal-header">
<div class="pull-right">
<button class="btn btn-danger btn-xs" data-dismiss="modal" title="Close dialog"> Close </button>
</div>
<h5 class="modal-title"> <i class="fa fa-download"></i> Download Contents: ' .$y->project_name. '</h5>
</div><!--/.modal-header-->
<div class="modal-body">'
.$this->download_contents($id). //calling the first function
'</div>
</div>
</div>
</div>';
} else {
return '<b style="color: red">No content uploaded yet.</b>';
}
}
第二个函数被传递给控制器并加载到视图中(带有一些其他信息)。现在我知道代码点火器的查询逻辑,而result()应该返回多于1行。我错过了什么?
答案 0 :(得分:1)
试试这个
public function download_contents($id) {
$the_contents = $this->db->get_where('contents', array('request_id' => $id));
$count = 1;
$loop_result="";
foreach ($the_contents->result() as $y) {
$file_name = $y->file_name;
$download_path = base_url('assets/client/contents/'.$file_name);
$loop_result .= '<p>' .$count++. '. ' .$file_name. '
<a class="btn btn-primary btn-xs" href="' .$download_path. '" title="Download Content">Download</a></p>';
}
return $loop_result;
}