这是我的 report_model 中的request_report函数,我的视图中的代码表格数据如何通过控制器传递
function request_report($from, $to, $member_filter )
{
$this->db->select('requests.request_id,items.item_type,items.quantity,items.item_unit,items.item_name, requests.item_id, requests.quantity_requested, requests.quantity_delivered, requests.purpose');
$this->db->from('requests', 'items');
$this->db->join('items', 'items.item_id = requests.item_id');
$this->db->where('created_time >=', $from);
$this->db->where('created_time <=', $to);
if ($member_filter != 'null') $this->db->where('created_by', $member_filter);
$query = $this->db->get();
if ($query->num_rows() > 0 ) {
echo '<table id="requests" class="table table-bordered table-striped">
<thead>
<tr>
<th>#</th>
<th>Category</th>
<th>Items</th>
<th>Quantity Requested</th>
<th>Quantity Available</th>
<th>Quantity Delivered</th>
<th>Purpose</th>
</tr>
</thead>
<tbody>';
foreach ($query->result() as $row) {
echo '<tr>';
echo '<td>';
echo $row->request_id;
echo '</td>';
echo '<td>';
echo $this->get_item_type_name($row->item_type);
echo '</td>';
echo '<td>';
echo $row->item_name;
echo '</td>';
echo '<td>';
echo $row->quantity . " " . $this->get_unit_measurement($row->item_unit);
echo '</td>';
echo '<td>';
echo $row->quantity_requested . " " . $this->get_unit_measurement($row->item_unit);
echo '</td>';
echo '<td>';
echo $row->quantity_delivered . " " . $this->get_unit_measurement($row->item_unit);
echo '</td>';
echo '<td>';
echo $row->purpose;
echo '</td>';
echo '</tr>';
}
echo '</tbody>
</table>';
}
else{
return '<h4 style="text-align: center; padding: 37px;"> No Matching Requests Found </h4>';
}
}
这是我的观点
<div class="col-sm-12">
<?php echo $this->report_model->request_report($from, $to, $member_filter)>
</div>
我的问题是如何通过控制器将数据从模型传递到视图,而不仅仅是直接在视图中调用模型,我需要模型中的表格数据才能查看,我正在寻找任何帮助,谢谢!!
答案 0 :(得分:0)
我的问题是如何将数据从模型传递到视图 控制器,不只是直接在视图中调用模型,我需要 模型中的表格数据在视图中,我正在寻找任何帮助,谢谢!!
在你的控制器中说方法是index()
<?php
class Site extends CI_Controller{
function index()
{
// this you can also put in __construct
// if you want to share same model across other methods
$this->load->model('report_model');
// And call your model function like below
$data = $this->report_model->request_report('2015-12-10', '2016-03-10', 'some_user');
// load view
$this->load->view('bootstrap_view',array('model_output' => $data));
}
}
并在您看来,说bootstrap_view.php
<div class="col-sm-12">
<?php echo $model_output;>
</div>
另请注意,您可以在codeigniter中使用表类,您可以在其中设置您感兴趣的模板,有关详细信息,请参阅以下链接