这是smarty设置的模板路径 <?php require_once("smarty.class.php"); class MySmarty extends Smarty{ var $path; function MySmarty($path='./'){ Smarty::smarty(); $this->path=$path; //$this->template_dir=$path."180du/"; $this->compile_dir=$path."180du/include/smarty/templates_c/"; $this->config_dir = $path."180du/include/smarty/configs/"; $this->cache_dir = $path."180du/include/smarty/cache/"; $this->left_delimiter = "<!--{"; $this->right_delimiter = "}-->"; }//end fun MySmarty
function setTpl($path=''){ //global $this; $this->path=$path; $this->template_dir=$this->path.$path; }}//end class mySmarty ?>//smarty $smarty=new MySmarty("$pathdir/"); $smarty->setTpl("templates/"); $smarty->assign("array",$array); $smarty->display("index.html"); 出错说我找不到模板资源 Warning: Smarty error: unable to read resource: "index.html" in E:\ACCESS-CLIENT\180du.com\httpd\180du\include\smarty\smarty.class.php on line 1144
想兼容
把'\'换成'/'不就行了,window 下和liunx下是不一样的,但是'/'这个可以兼容W && L;
<?php
require_once("smarty.class.php");
class MySmarty extends Smarty{
var $path;
function MySmarty($path='./'){
Smarty::smarty();
$this->path=$path;
//$this->template_dir=$path."180du/";
$this->compile_dir=$path."180du/include/smarty/templates_c/";
$this->config_dir = $path."180du/include/smarty/configs/";
$this->cache_dir = $path."180du/include/smarty/cache/";
$this->left_delimiter = "<!--{";
$this->right_delimiter = "}-->"; }//end fun MySmarty
function setTpl($path=''){
//global $this;
$this->path=$path;
$this->template_dir=$this->path.$path;
}}//end class mySmarty
?>//smarty
$smarty=new MySmarty("$pathdir/");
$smarty->setTpl("templates/");
$smarty->assign("array",$array);
$smarty->display("index.html");
出错说我找不到模板资源
Warning: Smarty error: unable to read resource: "index.html" in E:\ACCESS-CLIENT\180du.com\httpd\180du\include\smarty\smarty.class.php on line 1144
你要访问的目录为 ./180du/
两者结合起来就是
E:/ACCESS-CLIENT/180du.com/httpd/180du/180du/
当然不对啦$this->compile_dir=$path."include/smarty/templates_c/";
$this->config_dir = $path."include/smarty/configs/";
$this->cache_dir = $path."include/smarty/cache/";
我输出看了一下,路径怎么是这样的,这是什么原因?