#1 tanidea
这个现象是:模板文件里,一个DIV的CSS背景图片引入失败,导致PHP的 get_included_files() 函数记录不同。下面上的我测试代码。
1. 首先在入口文件 index.php 最后加入 file_put_contents('file',var_export(get_included_files(),true)); 记录本次运行所引入的所有文件
index.php代码
define('APP_DIR', realpath('./'));2. 新建一个模块,我用 admin 模块测试。protected\controller\admin
require(APP_DIR.'/protected/lib/speed.php');
file_put_contents('file',var_export(get_included_files(),true));//生成的记录文件是 file 没有后缀
3. 新建一个控制器和两个方法,我用user控制器测试
UserController.php代码
class UserController extends Controller{4. 最后新建两个模板文件,放在 protected\view\admin 下面
function actioncss(){
$this->display('admin/css.html'); //css.html模板文件
}
function actionnocss(){
$this->display('admin/nocss.html'); //nocss.html模板文件
}
}
css.html代码
nocss.html代码untitle
有CSS的
代码很简单,一个php文件,两个html文件,两个模块文件不同之处在于:css.html有css样式指定 bg { background-image:url(./img/bg0.jpg);} 但这个背景图片是不存在的。nocss.html没有任何css样式指定untitle
没有CSS的
下面就看测试结果
访问 index.php?m=admin&c=user&a=css
file 文件的记录是 (结果就是:有css的,没有正确显示引入admin模块下的 UserController.php)
array (访问 index.php?m=admin&c=user&a=nocss
0 => 'D:\\WAMP\\www\\speed\\index.php',
1 => 'D:\\WAMP\\www\\speed\\protected\\lib\\speed.php',
2 => 'D:\\WAMP\\www\\speed\\protected\\config.php',
3 => 'D:\\WAMP\\www\\speed\\protected\\controller\\MainController.php',
4 => 'D:\\WAMP\\www\\speed\\protected\\controller\\BaseController.php',
5 => 'D:\\WAMP\\www\\speed\\protected\\include\\functions.php',
6 => 'D:\\WAMP\\www\\speed\\protected\\tmp\\60155440c01a7c960d42ccd04744cfd5.1466823477.layout.html.php',
7 => 'D:\\WAMP\\www\\speed\\protected\\tmp\\cd30298c7f199ab9b41324e3c1d6341c.1467940570.main_index.html.php',
)
file 文件的记录是 (结果就是:没有css的,正确显示引入admin模块下的 UserController.php)
array (
0 => 'D:\\WAMP\\www\\speed\\index.php',
1 => 'D:\\WAMP\\www\\speed\\protected\\lib\\speed.php',
2 => 'D:\\WAMP\\www\\speed\\protected\\config.php',
3 => 'D:\\WAMP\\www\\speed\\protected\\controller\\admin\\UserController.php',
4 => 'D:\\WAMP\\www\\speed\\protected\\include\\functions.php',
5 => 'D:\\WAMP\\www\\speed\\protected\\tmp\\d58c70a96d43aed1dbbdd97b431ec285.1468220112.nocss.html.php',
)
可以看到,同是访问 admin模块 user控制器,CSS有错的,没有引入admin模块下的的文件,没有CSS样式的,才正确显示引入admin模块下的 UserController.php
虽然访问的URL显示结果都正确,但get_included_files() 应该不会记录错吧? 这如何解释?jake.
2016-07-11 15:56:10