douwu7168 2018-11-19 21:47
浏览 66
已采纳

CodeIgniter子目录中的视图

Class

public function load($page = 'resources')
{
    if ( ! file_exists(APPPATH.'views/resources/'.$page.'.php'))
    {
        // Whoops, we don't have a page for that!
        show_404();
    }

    $data['title'] = ucfirst($page); // Capitalize the first letter

    $this->load->view('templates/header', $data);
    $this->load->view('resources/multiplication'.$page, $data);
    $this->load->view('templates/footer', $data);

}

Directory

-Application
--views
---resources
----multiplication
-----selector.php

I'm trying to load selector.php with localhost://resources/load/selector but it just shows a 404. I can't get the classes to work with sub directories in the view folders.

If I move selector into /resources, it loads no problem. How can I get load method to load selector.php?

</div>
  • 写回答

2条回答 默认 最新

  • dongluxin2452 2018-11-19 21:57
    关注

    That's because before you load your view you have a condition to load the 404 error. You should remove that condition or edit it to your real path:

    public function load($page = 'resources')
        {
             if ( ! file_exists(APPPATH.'views/resources/multiplication/'.$page.'.php')) //Just added the multiplication to make it the right path
        {
                // Whoops, we don't have a page for that!
                show_404();
        }
    
        $data['title'] = ucfirst($page); // Capitalize the first letter
    
        $this->load->view('templates/header', $data);
        $this->load->view('resources/multiplication'.$page, $data);
        $this->load->view('templates/footer', $data);
    
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)