我有一个设置智能实例的课程:
class View {
protected $templateEngine;
protected $templateExtension = '.tpl';
public function __construct(){
global $ABS_PUBLIC_PATH;
global $ABS_PUBLIC_URL;
$this->templateEngine = new Smarty();
$this->templateEngine->error_reporting = E_ALL & ~E_NOTICE;
$this->templateEngine->setTemplateDir($ABS_PUBLIC_PATH . '/templates/');
$this->templateEngine->setCompileDir($ABS_PUBLIC_PATH . '/templates_c/');
$this->templateEngine->assign('ABS_PUBLIC_URL', $ABS_PUBLIC_URL);
if(isset($_SESSION['loggedIn'])){
$this->assign('session', $_SESSION);
}
}
public function assign($key, $value){
$this->templateEngine->assign($key, $value);
}
public function display($templateName){
$this->templateEngine->display($templateName . $this->templateExtension);
}
public function fetch($templateName){
$this->templateEngine->fetch($templateName . $this->templateExtension);
}
}
然后在我的函数中,我使用这样的类:
public function showMeSomething()
{
$view = new View();
$view->assign('session', $_SESSION);
$view->display('header');
$view->display('index');
$view->display('footer');
}
现在,我正在尝试将一些数据提取到变量中,以便从我的模板文件中发送电子邮件。不幸的是,下面的var_dump(两者都)输出NULL
- 即使引用的模板文件中包含很多HTML。此外,将下面的fetch
更改为display
将正确显示模板文件。所以,问题当然在于fetch命令。我不知道该怎么做才能继续调试。
function emailPrep($data,){
$mailView = new View();
$emailHTML = $mailView->fetch('myEmail');
var_dump($mailView->fetch("myEmail"));
var_dump($emailHTML);
}
答案 0 :(得分:1)
您的代码必须
public function fetch($templateName){
return $this->templateEngine->fetch($templateName . $this->templateExtension);
}