【发布时间】:2016-04-11 16:56:17
【问题描述】:
我有一个电子邮件模板 onecode.mail.php
我打来的电话
$body = $view->render(
'template',
compact('users','oneCode','username'),
array(
'controller' => 'users',
'template'=>'onecode',
'type' => 'mail',
'layout' => false
)
);
$transport = Swift_MailTransport::newInstance();
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance();
$message->setSubject("Sign in password");
$message->setFrom(array(NOREPLY => 'Sign in password'));
$message->setTo($email);
$message->setBody($body,'text/html');
$mailer->send($message);
onecode.mail.php 包含
<?=$t('Login Email Password')?>
<?=$oneCode?>
我在处理此请求时遇到错误:
<b>Fatal error</b>: Function name must be a string in <b>app\resources
\tmp\cache\templates
\template_views_users_onecode.mail_0_1460392715_2266.php</b> on line <b>1</b><br/>
翻译在所有 .html.php 文件中都能完美运行,但在 .email.php 的模板中却不行
应该怎么做?任何建议,感谢您的帮助。
【问题讨论】:
-
表示
$t的值不是函数名。在 onecode.mail.php 中尝试echo $t;看看它是什么。你在哪里初始化它? -
我按照你的建议试过了,没有改错。我在 .html.php 文件中使用时从未初始化它,所以对于 .mail.php 我也没有初始化它。它在锂库\lithium\g11n\Message.php 之一中初始化。我尝试调用该库使用 \lithium\gmm1\Message;没有帮助!
-
好的,感谢您的尝试。我不熟悉锂库。如果这与您的其他文件不同,可能是由于
'type' => 'mail'。也许在你的 onecode.mail.php 前面加上<?php extract(Message::aliases()); ?>可以修复它? (找到它here)。无论如何,祝你好运! -
谢谢!!!通过将这两行添加到模板 email.php 中,它起作用了。使用锂\g11n\消息;提取(消息::别名());
标签: php email templates lithium