【问题标题】:PHP Included files writing their own content from Importer valuesPHP 包含的文件从 Importer 值写入自己的内容
【发布时间】:2010-04-03 11:03:09
【问题描述】:

我有一个 index.php 文件,其中包含几个外部文件:

“内容/模板/id1/template.php” “内容/模板/id2/template.php” “内容/模板/id3/template.php” 等等

所有这些文件都被动态加载到 index.php 中(它读取“templates”目录中的所有文件夹,然后包含每个“template.php”文件)。

我想让“template.php”在所有“id1,id2,id3”文件夹中都有相同的代码,但要从 index.php 加载值,具体取决于它所在的文件夹..

我该怎么做? 谢谢!

【问题讨论】:

    标签: php dynamic include


    【解决方案1】:

    你可以像这样让每个模板找出它的目录:

    /id1/template.php

     $path = dirname(__FILE__);
     $id  = pathinfo($path,  PATHINFO_BASENAME);
    
     echo "Hi, I'm the template in $id!";  // Will output "id1"
    

    【讨论】:

    • 非常感谢!像我这样的新手生活很艰难:D
    • 哦,还有一个问题。我将如何编写从 index.php 加载的代码让我们说 $id1_title 的值(“id1”与放置它的文件夹相同)?
    • 在 About.com 上找到它 $test = "success"; $open = "$"; $关闭 = ";"; $primary = "测试"; $ID = "$open$primary$close";回显$ID;再次感谢佩卡!
    猜你喜欢
    • 2012-04-15
    • 2011-11-30
    • 1970-01-01
    • 2020-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-10
    • 1970-01-01
    相关资源
    最近更新 更多