继承父类然后重写其私有属性是不可能的。在不改其源代码的情况下,这就需要使用smarty提供的两个接口函数。
setTemplateDir()和setCompileDir()
配置如下:
class Mysmarty extends Smarty{
publicfunction __construct(){
parent::__construct();
$this->setTemplateDir= './templates';
$this->setCompileDir= './compile';
}
}
源码中如下:
private $template_dir = array('./templates/');
private $compile_dir = './templates_c/';
public functionsetTemplateDir($template_dir)
{
$this->template_dir = array();
foreach ((array) $template_dir as $k => $v) {
$this->template_dir[$k] = rtrim($v, '/\\') . DS;
}
$this->joined_template_dir = join(' # ',$this->template_dir);
return $this;
}
public function setCompileDir($compile_dir)
{
$this->compile_dir = rtrim($compile_dir, '/\\') . DS;
if (!isset(Smarty::$_muted_directories[$this->compile_dir])) {
Smarty::$_muted_directories[$this->compile_dir] = null;
}
return $this;
}