smarty如何使用绝对路径设置template_dir和compile_dir
代码编写如下:<?phpinclude_once'smarty/Smarty.class.php';$smarty=newSmarty();$smarty->config...
代码编写如下:
<?php
include_once 'smarty/Smarty.class.php';
$smarty = new Smarty();
$smarty->config_dir = "smarty/Config_File.class.php";
/*********** 代码1 *********************/
/*$smarty->compile_dir = "D:/wamp/www/testsmarty/templates_c";
$smarty->template_dir = "D:/wamp/www/testsmarty/templates"; */
/*********** 代码1结束 *********************/
echo "D:/wamp/www/testsmarty/templates_c";
echo '<br />';
echo $_SERVER['DOCUMENT_ROOT'].'/testsmarty/templates_c';
/*************代码2******************/
$smarty -> compile_dir = $_SERVER['DOCUMENT_ROOT'].'/testsmarty/templates_c';
$smarty -> templates_dir = $_SERVER['DOCUMENT_ROOT'].'/testsmarty/templates';
/*************代码2结束***************/
?>
使用代码1部分可以得到正确结果,而使用代码2会出现如下错误:
Warning: Smarty error: unable to read resource: "test.html" in D:\wamp\www\testsmarty\smarty\Smarty.class.php on line 1095
Warning: Smarty error: unable to read resource: "test.html" in D:\wamp\www\testsmarty\smarty\Smarty.class.php on line 1095
而通过输出可以看出中间的两个echo是一样的,可是为什么结果却不一样的?如果代码2不正确,该如何通过代码自动获取绝对路径呢? 展开
<?php
include_once 'smarty/Smarty.class.php';
$smarty = new Smarty();
$smarty->config_dir = "smarty/Config_File.class.php";
/*********** 代码1 *********************/
/*$smarty->compile_dir = "D:/wamp/www/testsmarty/templates_c";
$smarty->template_dir = "D:/wamp/www/testsmarty/templates"; */
/*********** 代码1结束 *********************/
echo "D:/wamp/www/testsmarty/templates_c";
echo '<br />';
echo $_SERVER['DOCUMENT_ROOT'].'/testsmarty/templates_c';
/*************代码2******************/
$smarty -> compile_dir = $_SERVER['DOCUMENT_ROOT'].'/testsmarty/templates_c';
$smarty -> templates_dir = $_SERVER['DOCUMENT_ROOT'].'/testsmarty/templates';
/*************代码2结束***************/
?>
使用代码1部分可以得到正确结果,而使用代码2会出现如下错误:
Warning: Smarty error: unable to read resource: "test.html" in D:\wamp\www\testsmarty\smarty\Smarty.class.php on line 1095
Warning: Smarty error: unable to read resource: "test.html" in D:\wamp\www\testsmarty\smarty\Smarty.class.php on line 1095
而通过输出可以看出中间的两个echo是一样的,可是为什么结果却不一样的?如果代码2不正确,该如何通过代码自动获取绝对路径呢? 展开
3个回答
展开全部
/* 取得当前的根目录 */
define('ROOT_PATH', str_replace('include/init.php[换成当前文件的相对路径]', '', str_replace('\\', '/', __FILE__)));
$smarty->template_dir = ROOT_PATH . 'themes/default';
$smarty->cache_dir = ROOT_PATH . 'temp/caches';
$smarty->compile_dir = ROOT_PATH . 'temp/compiled';
define('ROOT_PATH', str_replace('include/init.php[换成当前文件的相对路径]', '', str_replace('\\', '/', __FILE__)));
$smarty->template_dir = ROOT_PATH . 'themes/default';
$smarty->cache_dir = ROOT_PATH . 'temp/caches';
$smarty->compile_dir = ROOT_PATH . 'temp/compiled';
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询