D:\xampp\htdocs\MyLocalShop\common\templates\smartyTemplate.class.php:<?php
/**
 * 自创Smarty扩展类
 * @author Administrator
 */ if (IN_MLS !== true) die('不能访问此脚本!'); require_once 'D:/xampp/php/Smarty/libs/Smarty.class.php';

class smartyTemplate {
private $smarty; // Smarty对象

/**
 * 初始化Smarty对象
 * @param none
 * @return none
 */
public function __construct() {
$this->smarty = new Smarty();
$this->smarty->template_dir = "D:/xampp/php/Smarty/demo/templates/";
$this->smarty->compile_dir = "D:/xampp/php/Smarty/demo/compile_dir/";
$this->smarty->config_dir = "D:/xampp/php/Smarty/demo/configs/";
$this->smarty->cache_dir = "D:/xampp/php/Smarty/demo/cache/";
}

/**
 * 设置Smarty变量或常量或数组
 * @param array/string $var 变量名
 * @param string $value 变量值
 * @return none
 */
public function assignVar($var, $value) {
$this->smarty->assign($var, $value);
}

/**
 * 用于显示Smarty模板
 * @param string $template 模板名
 * @return none
 */
public function showTemplate($template) {
$this->smarty->display($template);
}
}
?>
D:\xampp\htdocs\MyLocalShop\front\includes\index.php:<?php
/**
 * 前台页面首页文件
 * @copyright (C) 2013-2014 MyLocalShop
   * @license http://www.baidu.com/
   * @lastmodify 2013-01-07
 */ //session_start();
//header('Cache-control: private'); define('IN_MLS', true); require '../../load.class.php';
require '../../common/common.php';
require '../../common/languages/zh_CN/front/common.php';

//echo CACHE_PATH;
//echo 342;

// 载入Smarty
//if (Load_MLS::Load('common/templates/', 'smartyTemplate.class.php'))
include '../../common/templates/smartyTemplate.class.php';

$frontSmarty = new smartyTemplate();


$frontSmarty->assignVar('pageTitle', $LANG['pageTitle']);
$frontSmarty->showTemplate('front-index.tpl');
?>输出错误:Fatal error: Uncaught exception 'SmartyCompilerException' with message 'Syntax Error in template "D:\xampp\php\Smarty\demo\templates\pageHeader.tpl" on line 29 "&lt;a href=&quot;{$}&quot;&gt;&lt;img src=&quot;&quot; alt=&quot;home&quot;/&gt;&lt;/a&gt;&amp;nbsp;" - Unexpected "}", expected one of: "{" , "identifier"' in D:\xampp\php\Smarty\libs\sysplugins\smarty_internal_templatecompilerbase.php:656 Stack trace: #0 D:\xampp\php\Smarty\libs\sysplugins\smarty_internal_templateparser.php(3139): Smarty_Internal_TemplateCompilerBase->trigger_template_error() #1 D:\xampp\php\Smarty\libs\sysplugins\smarty_internal_templateparser.php(3204): Smarty_Internal_Templateparser->yy_syntax_error(17, '}') #2 D:\xampp\php\Smarty\libs\sysplugins\smarty_internal_smartytemplatecompiler.php(105): Smarty_Internal_Templateparser->doParse(17, '}') #3 D:\xampp\php\Smarty\libs\sysplugins\smarty_internal_templatecompilerbase.php(192): Smarty_Internal_SmartyTemplateCompiler->doCompile('<meta http-equi...') #4 D:\xampp\php\Smarty\libs\sysplugins\smar in D:\xampp\php\Smarty\libs\sysplugins\smarty_internal_templatecompilerbase.php on line 656
为什么怎么改都错误?templatesphpfunctionexceptionstring

解决方案 »

  1.   

    而且index.php中的22行注释除去,就不能导入smartyTemplate.class.php了,这表示if中语句返回false,但按道理没理由返回false的啊!!这if语句中的Load_MLS::Load定义在D:\xampp\htdocs\MyLocalShop\load.class.php:<?php
    /**
     * MyLocalShop 目录文件装载器
     * @author Administrator
     *
     */
    if (IN_MLS !== true) die('不能访问此脚本!'); class Load_MLS {

    /**
     * 检查完整目录文件路径是否存在,存在则返回目录文件路径,不存在则返回false
     * @param string $file_url 目录文件组成的完整URL路径
     * @return 存在则返回目录文件路径string,不存在则返回false
     */
    private function hasFile($file_url) {
    if (file_exists($file_url))
    return $file_url;
    else
    return false;
    }



    /**
     * __autoload()函数
     * @param string $name 被加载的对象
     * @return none
     */
    /*function __autoload($name) {
    require_once $name;
    }*/

    /**
     * 检查php版本是否大于5.1并是否支持__autoload()
     * @param none
     * @return 支持返回true,不支持返回false
     */
    /*public static function hasAutoLoad() {
    if ((PHP_VERSION >= '5.1') && (function_exists('__autoload')))
    return true;
    else
    return false;
    }*/


    /**
     * 自动加载对象
     * @param string $name 被自动加载的对象
     * @return none
     */
    /*public static function AutoLoad($name) {
    if (Load_MLS::hasAutoLoad())
    self::__autoload($name);
    }*/



    /**
     * 把指定目录及文件组成一个完整的路径
     * @param string $dir_url 完整目录URL
     * @param string $file 文件
     * @return 成功返回完整URL,失败返回false
     */
    public static function Load($dir_url, $file) {
    $url = self::hasFile($dir_url.$file);
    //echo $url;
    if ($url !== false)
    return $url;
    else {
    echo false;
    }
    }


    }
    ?>
    表示检测smartyTemplate.class.php是否存在,不存在则返回false。我试过在index.php中的22行if语句== false就可以成功导入。该怎么办呢?我到底哪里出错了?
      

  2.   

    没封口吧?? die下看是模板问题还是class类的问题
      

  3.   

    你贴出的错误信息不都是 smarty 的吗?
    Fatal error: Uncaught exception 'SmartyCompilerException' with message 'Syntax Error in template "D:\xampp\php\Smarty\demo\templates\pageHeader.tpl" on line 29 "....是你的模板有问题