CodeIgniter 目錄輔助函數(shù)

2018-07-21 15:43 更新

目錄輔助函數(shù)

目錄輔助函數(shù)文件包含了一些幫助你處理目錄的函數(shù)。

加載輔助函數(shù)

該輔助函數(shù)通過(guò)下面的代碼加載:

$this->load->helper('directory');

可用函數(shù)

該輔助函數(shù)有下列可用函數(shù):

directory_map($source_dir[, $directory_depth = 0[, $hidden = FALSE]])

參數(shù):

  • $source_dir (string) -- Path to the source directory
  • $directory_depth (int) -- Depth of directories to traverse (0 = fully recursive, 1 = current dir, etc)
  • $hidden (bool) -- Whether to include hidden directories

返回: An array of files

返回類(lèi)型: array

舉例:

$map = directory_map('./mydirectory/');

注解

路徑總是相對(duì)于你的 index.php 文件。

如果目錄內(nèi)含有子目錄,也將被列出。你可以使用第二個(gè)參數(shù)(整數(shù)) 來(lái)控制遞歸的深度。如果深度為 1,則只列出根目錄:

$map = directory_map('./mydirectory/', 1);

默認(rèn)情況下,返回的數(shù)組中不會(huì)包括那些隱藏文件。如果需要顯示隱藏的文件, 你可以設(shè)置第三個(gè)參數(shù)為 true

$map = directory_map('./mydirectory/', FALSE, TRUE);

每一個(gè)目錄的名字都將作為數(shù)組的索引,目錄所包含的文件將以數(shù)字作為索引。 下面有個(gè)典型的數(shù)組示例:

Array (
    [libraries] => Array
        (
            [0] => benchmark.html
            [1] => config.html
            ["database/"] => Array
                (
                    [0] => query_builder.html
                    [1] => binds.html
                    [2] => configuration.html
                    [3] => connecting.html
                    [4] => examples.html
                    [5] => fields.html
                    [6] => index.html
                    [7] => queries.html
                )
            [2] => email.html
            [3] => file_uploading.html
            [4] => image_lib.html
            [5] => input.html
            [6] => language.html
            [7] => loader.html
            [8] => pagination.html
            [9] => uri.html
        )
以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)