まず、CodeIgniter へようこそ。それは支配します。今...
ディレクトリを実際に処理するには、次のようなコントローラー関数が必要です。
public function dir_to_array($dir, $separator = DIRECTORY_SEPARATOR, $paths = 'relative')
{
$result = array();
$cdir = scandir($dir);
foreach ($cdir as $key => $value)
{
if (!in_array($value, array(".", "..")))
{
if (is_dir($dir . $separator . $value))
{
$result[$value] = $this->dir_to_array($dir . $separator . $value, $separator, $paths);
}
else
{
if ($paths == 'relative')
{
$result[] = $dir . '/' . $value;
}
elseif ($paths == 'absolute')
{
$result[] = base_url() . $dir . '/' . $value;
}
}
}
}
return $result;
}
次のような結果を返すには、その関数を呼び出す必要があります。
$modules['module_files'] = $this->dir_to_array(APPPATH . 'modules');
これにより、結果が $modules という変数に入れられます。これは、好きな方法で使用できます。通常は、次のようなビューに入れます。
$this->load->view('folder/file', $modules);
オプションの 3 番目のパラメーター TRUE を load->view 関数に指定すると、そのビューの結果が再び返され、好きな場所で使用できます。それ以外の場合は、呼び出した場所にエコー アウトされます。ビューは次のようになります。
<?php
if (isset($module_files) && !empty($module_files))
{
$out = '<ul>';
foreach ($module_files as $module_file)
{
if (!is_array($module_file))
{
// the item is not an array, so add it to the list.
$out .= '<li>' . $module_file . '</li>';
}
else
{
// Looping code here, as you're dealing with a multi-level array.
// Either do recursion (see controller function for example) or add another
// foreach here if you know exactly how deep your nested list will be.
}
}
$out .= '</ul>';
echo $out;
}
?>
構文エラーについては確認していませんが、問題なく動作するはずです。お役に立てれば..