【问题标题】:View doesn't load视图不加载
【发布时间】: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-&gt;load-&gt;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


【解决方案1】:

在屏幕上单击鼠标右键 - 检查元素。在元素面板中,选择应该在屏幕上的表格。如果由于某种原因没有关闭显示样式,请检查样式面板。

您还可以检查它在屏幕上的位置(如果它是可见的),以便您能够诊断该元素是否实际上在屏幕尺寸中。

【讨论】:

  • 感谢回复,它应该跳转到下一个 URL,我在提交表单时从 [::1]/spm/admin 触发它应该转到 [::1] /spm/report/vw_excel。但它会保留在当前页面上。
  • 在控制台中检查 - 是否有任何 javascript 错误不允许它继续执行?或..检查页面是否实际提交或什么。如果出现 Javascript 错误,它可能会阻止页面执行表单提交。如果提交的内容相同,则需要验证/检查表单/操作 URL。
  • 当我提交表单“检测到慢速网络。加载时将使用后备字体:chrome-”时,控制台上只有一个报告
  • 检查网络标签。看看有没有url进来?检查您指定为提交的按钮类型。它可能是一个不会触发提交操作的简单按钮。
猜你喜欢
  • 1970-01-01
  • 2015-12-20
  • 2017-11-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多