【问题标题】:$t function does not work in lithium email template$t 函数在锂电子邮件模板中不起作用
【发布时间】: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' =&gt; 'mail'。也许在你的 onecode.mail.php 前面加上&lt;?php extract(Message::aliases()); ?&gt; 可以修复它? (找到它here)。无论如何,祝你好运!
  • 谢谢!!!通过将这两行添加到模板 email.php 中,它起作用了。使用锂\g11n\消息;提取(消息::别名());

标签: php email templates lithium


【解决方案1】:

请在您的模板中添加以下行:

<?php
use lithium\g11n\Message;
extract(Message::aliases());
?>
<?=$t('Login Email Password')?>

您应该能够获得所需语言的翻译

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-11
    • 2016-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多