Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在控制器函数中加载目录作为视图:Codeigniter_Php_Codeigniter_View_Controller - Fatal编程技术网

Php 如何在控制器函数中加载目录作为视图:Codeigniter

Php 如何在控制器函数中加载目录作为视图:Codeigniter,php,codeigniter,view,controller,Php,Codeigniter,View,Controller,我有一个文件夹,其中包含一些API文件,我已将整个文件夹放入视图目录,现在我想加载整个文件夹作为视图,而不是任何单个文件 例如,我有一个文件夹名review,因此我想将整个文件夹作为视图加载 我尝试过一些东西,但每次在目录后添加.php扩展名时,我都可以这样做:我有以下函数 enter code here public function load_root(){ $root_url = $this->load->view('/review/'); } 使用scandir扫描文

我有一个文件夹,其中包含一些API文件,我已将整个文件夹放入视图目录,现在我想加载整个文件夹作为视图,而不是任何单个文件

例如,我有一个文件夹名review,因此我想将整个文件夹作为视图加载

我尝试过一些东西,但每次在目录后添加.php扩展名时,我都可以这样做:我有以下函数

enter code here public function load_root(){
 $root_url = $this->load->view('/review/');
  }

使用
scandir
扫描文件夹中的所有文件

$dir    = '/folder_name';
$files = scandir($dir);

print_r($files);// will print all the files inside the folder.

使用foreach并加载文件夹中的所有视图。

您需要加载
helper('directory')

试一试


注意:以上代码适用于CodeIgniter 3+

u要从该文件夹一次加载所有文件??实际上我需要整个目录作为一个路径,我必须将其用作url。它是否只包含.php文件?不,它包含所有其他文件,如css图像。我必须创建一个路径,如下所示:这是我的baseurl:我有一个用户作为控制器然后在该控制器中,我有一个函数load_root,它必须从视图中加载整个目录。
$this->load->helper('directory');
$files = directory_map('reviews')); // Directory Name here

foreach($files as $file)
{
    $this->load->view('/review/'.$file);
}