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条)

报告相同问题?