1
我正在为我的CodeIgniter项目编写一个template_loader。像往常一样,我需要几个安全层为我的模板。其中一个,即第一个,是检查文件是否存在。CodeIgniter检查文件
现在,我的问题是:我无法配置给模板加载器的地址。当我使用名为'include()'的简单php函数时,它可以工作,但是使用我的template_loader函数,它无法工作。
这里是我的实际网页(的index.php):
<?php
/**
Add the page-suitable template from in folder.
**/
$this->template_loader->load_template('inc/temp_one_col.php');
// include('inc/temp_one_col.php');
?>
这里是我的阶级和template_loader:
class Template_loader
{
function load_template ($arg)
{
$base_name = basename($arg);
$CI =& get_instance();
if(file_exists($arg) === true)
{
echo 'it is also good.';
if (pathinfo($base_name, PATHINFO_EXTENSION) == 'php' ||
pathinfo($base_name, PATHINFO_EXTENSION) == 'html'
)
{
$file_name_check = substr($base_name, 0, 4);
if($file_name_check === TEMP_FILE_INDICATOR)
{
include($arg);
}
else
{
redirect($CI->base_url . '/error/show_problem');
}
}
else
{
redirect($CI->base_url . '/error/show_problem');
}
}
else
{
redirect($CI->base_url . '/error/show_problem');
}
}
}
请参阅http://stackoverflow.com/questions/6188727/how -to-add-autoload-function-to-codeigniter(用于自动加载功能,标记为答案) – Kyslik
对不起,你好像误解了我的问题,或者我误解了你的回复。我已经在控制器中加载了库,唯一的错误是地址问题。因为file_exists没有找到参数中给出的文件。 –
哦,我看到了,试试'base_url($ arg);'('base_url()'在url helper中)。我相信,只要给'file_exists()'提供了一个错误的路径,甚至可以尝试使用CIs constanst作为'APPPATH' ..在这里查看完整列表http://ellislab.com/codeigniter/user-guide/general/reserved_names .html – Kyslik