继承smarty类时遇到的问题,求指导!!
我直接把smarty的libs目录拷进测试项目中,测试项目很简单,有两个文件demo.php和init.inc.php,然后我在init.inc.php做一些配置,比如界定符、模板目录之类,如果是以这种方式:
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->
<?php
include_once './libs/Smarty.class.php';
$tpl=new Smarty;
$tpl->left_delimiter="<!--{";
$tpl->right_delimiter="}-->";
?>
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->
<?php
require_once 'init.inc.php';
$title="this is a title";
$content="this is my content";
$tpl->assign("title",$title);
$tpl->assign("content",$content);
$tpl->display("default/test.tpl");
?>
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->
<?php
include_once './libs/Smarty.class.php';
class mySmarty extends Smarty{
function mySmarty(){
$this->Smarty();
$this->template_dir="./templates/";
$this->compile_dir="./templates_c/";
$this->config_dir="./configs/";
$this->cache_dir="./cache/";
$this->caching=true;
$this->left_delimiter="<!--{";
$this->right_delimiter="}-->";
$this->assign('app_name','mySmartyTest');
}
}
?>
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->
<?php
require_once 'init.inc.php';
$tpl=new mySmarty;
$title="this is a title";
$content="this is my content";
$tpl->assign("title",$title);
$tpl->assign("content",$content);
$tpl->display("default/test.tpl");
?>
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号