2016-04-11 43 views
1

我有一個電子郵件模板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模板中。

應該做什麼?任何建議,感謝您的幫助。

+0

這意味着'$ t'值不是一個函數名。嘗試'echo $ t;'在onecode.mail.php中看看它是什麼。你在哪裏初始化它? – Kenney

+0

我試着按照你的建議,沒有改變錯誤。當我在.html.php文件中使用時,我從未初始化它,因此.mail.php也沒有初始化它。 它在鋰庫\鋰\ g11n \ Message.php之一中初始化。我試過調用該庫 use \ lithium \ gmm1 \ Message; 沒有幫助! –

+1

好的,謝謝你的嘗試。我不熟悉Lithium庫。也許這是由於'type'=>'mail'',如果這不同於其他文件。也許預先添加'<?php extract(Message :: aliases()); ?>給你的onecode.mail.php修復它? (在[這裏]找到它(http://li3.me/docs/manual/common-tasks/globalization.md))。無論如何,祝你好運! – Kenney

回答

1

請添加以下行模板:

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

你應該能夠得到翻譯所需的語言