【问题标题】:How to fetch the folder names in codeigniter "views" folder如何获取codeigniter“views”文件夹中的文件夹名称
【发布时间】:2015-08-27 20:40:02
【问题描述】:

我正在尝试在 codeigniters 的“views”文件夹中获取文件夹名称,以创建一种模板类,该类将获取“view”中的所有文件夹名称...

我实际上想为我的网站创建一个默认模板,然后只需添加另一个模板文件夹(如 wordpress 主题)即可更改它

我该怎么做?

如果你能理解我在这里想说的话......

?php       

// declare the folder    
$ourDir = "/home/public_html/folderName";

// prepare to read directory contents    
$ourDirList = @opendir($ourDir);

// loop through the items    
while ($ourItem = readdir($ourDirList))    
{        
   // check if it is a directory    
   if (is_dir($ourItem))    
   {    
      echo "directory: $ourItem <br />";    
   }

   // check to see if it is a file    
   if (is_file($ourItem))    
   {    
      echo "file: $ourItem <br />";    
   }    
}

closedir($ourDirList);

?>

试过了,但没有用.. :(

【问题讨论】:

  • 你有没有得到任何错误?当你运行它时你会得到什么?
  • 您可能想要:stackoverflow.com/questions/17850535/…,但是,除了这种方法,我可以提出其他建议吗?主题名称/ids/其他数据...应该存储在数据库中(无论如何你都需要它)。主题名称应与您的视图文件夹中的文件夹名称相同......当您需要/选择另一个主题时,您可以轻松获取它: $this->load->view('themes/theme_from_db);在你的控制器中......要列出它,你需要它,只需列出数据库条目,并带有适当的图像......
  • 其实我什么也没得到,只是空白页
  • readdir() 期望参数 1 是资源,布尔值,因为这是我现在得到的错误 .. 与 closedir() 相同
  • edit您的问题在评论部分包含您提供的其他信息。

标签: php codeigniter templates view directory


【解决方案1】:

好吧,我刚刚找到了我的答案...

<?php
$dir =  APPPATH.'views/';

// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
    if ($dh = opendir($dir)) {
        while (($file = readdir($dh)) !== false) {
            if(filetype($dir . $file) == 'dir' && $file != '..' && $file != '.') {
                echo "filename: $file : filetype: " . filetype($dir . $file) . "<br>";
            }
        }
        closedir($dh);
    }
}
?>

这将回显所有文件夹...

【讨论】:

    猜你喜欢
    • 2012-05-23
    • 1970-01-01
    • 2015-10-17
    • 1970-01-01
    • 1970-01-01
    • 2016-03-25
    • 2020-12-19
    • 2021-10-31
    • 1970-01-01
    相关资源
    最近更新 更多