【发布时间】:2017-12-07 07:36:55
【问题描述】:
我想问一下观点 这里我有这样的控制器:(api.php)
public function export_excel() {
$date = new DateTime($this->input->post('date_fil'));
$curr_date = $date->format('Y-m-d ');
$user = $this->input->post('sales_name');
$checked = $this->input->post('cb_month');
$month = date('m');
if ((int) $checked == 1) {
$this->form_validation->set_rules('sales_name', 'Sales Name', 'required');
if ($this->form_validation->run() == false) {
$this->output->set_output(json_encode([
'result' => 0,
'error' => $this->form_validation->error_array()
]));
return false;
}
$this->db->select('t1.act_id, t2.login, t1.cust_name, t1.act_type, t1.act_detail, t1.date_added, t1.date_modified, t1.act_notes')
->from('activity as t1')
->join('user as t2', 't1.user_id = t2.user_id', 'LEFT')
->where('t2.login', $user)
->where('MONTH(t1.date_added)', $month);
$query = $this->db->get();
$result = $query->result_array();
$data = array('title' => 'Sales Report',
'user' => $result);
$this->load->view('report/vw_excel', $data);
// Selecting data by Date ----------------------------------------------
} else {
$this->form_validation->set_rules('sales_name', 'Sales Name', 'required');
$this->form_validation->set_rules('date_fil', 'Date', 'required');
if ($this->form_validation->run() == false) {
$this->output->set_output(json_encode([
'result' => 0,
'error' => $this->form_validation->error_array()
]));
return false;
}
$this->db->select('t1.act_id, t2.login, t1.cust_name, t1.act_type, t1.act_detail, t1.date_added, t1.date_modified, t1.act_notes')
->from('activity as t1')
->join('user as t2', 't1.user_id = t2.user_id', 'LEFT')
->where('t2.login', $user)
->where('DATE(t1.date_added)', $curr_date);
$query = $this->db->get();
$result = $query->result_array();
$data = array('title' => 'Sales Report',
'user' => $result);
$this->load->view('report/vw_excel', $data);
}
这是我要加载的视图,位于文件夹 (report/vw_excel) 下
<body>
<main>
<h1>Excel Report</h1>
<p><a href="<?php echo base_url('report/export_excel') ?>">Export to Excel</a></p>
<table border="1" width="100%">
<thead>
<tr>
<th>ID</th>
<th>Sales Name</th>
<th>Customer Name</th>
<th>Activity</th>
<th>Detail</th>
<th>Start Time</th>
<th>Finish Time</th>
<th>Note</th>
</tr>
</thead>
<tbody>
<?php $i=1; foreach($user as $xuser) { ?>
<tr>
<td><?php echo $xuser['act_id']; ?></td>
<td><?php echo $xuser['login']; ?></td>
<td><?php echo $xuser['cust_name']; ?></td>
<td><?php echo $xuser['act_type']; ?></td>
<td><?php echo $xuser['act_detail']; ?></td>
<td><?php echo $xuser['date_added']; ?></td>
<td><?php echo $xuser['date_modified']; ?></td>
<td><?php echo $xuser['act_notes']; ?></td>
</tr>
<?php $i++; } ?>
</tbody>
</table>
</main>
当我从其他视图文件夹调用它时(admin/admin_view)
onsubmit = 'api/export_excel',
这个"$this->load->view('report/vw_excel', $data);" 不会加载视图。
结果显示在浏览器的网络中,但视图未加载。 network view
有什么想法吗?谢谢。
【问题讨论】:
-
无论你有没有 $checked == 1 都会发生同样的事情吗?
-
我从您的屏幕截图中看到的一件事 - 您没有配置 $config['base_url'] ,因为您在链接中获得 :: 。
-
您应该问自己的是......脚本执行是否甚至到达了加载您的视图的语句?所以我会检查你的 $_POST 值 - 使用 var_dump()。检查您的 SQL 并确保它们得到结果并且您正在正确地测试这些结果。查看代码执行的去向...只是标准的调试过程...
-
是的,$checked == 1 也是如此,我的表单操作是 action="= site_url('api/export_excel') ?>" 和 $config['base_url'] ='';
-
罗杰,我会 var_dump 那个 $_post
标签: codeigniter