簡體   English   中英

子目錄中的CodeIgniter視圖

[英]CodeIgniter Views within sub directories

 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); } 

目錄

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

我正在嘗試使用localhost:// resources / load / selector加載selector.php,但它只顯示404。我無法使這些類與視圖文件夾中的子目錄一起工作。

如果我將選擇器移至/ resources,則不會加載任何問題。 我怎樣才能獲得加載方法來加載selector.php?

這是因為在加載視圖之前,您必須先加載404錯誤。 您應該刪除該條件或將其編輯為實際路徑:

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

    }

在兩種情況下,您只是在$page之前缺少/

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

    }

正如愛德華多(Eduardo)所暗示的那樣,僅供參考, show_404()並不是必需的,而且實際上更加令​​人困惑。 在CI中,如果視圖不存在,它將告訴您該視圖不存在。 但是,如果您想避免這樣的消息,您在做什么就可以了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM