加载期间 symfony twig 模板出现错误。
我需要包含这个吗:使用 Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
[InvalidArgumentException]
找不到模板“CrudBundle:email.html.twig”。
[Twig_Error_Loader]
找不到模板“CrudBundle:email.html.twig”。
[Twig_Error_Loader]
Unable to find template "CrudBundle:email.html.twig" (looked into: C:\xampp
\htdocs\sample\vendor\symfony\symfony\src\Symfony\Bridge\Twig/Resourc
es/views/Form).
这是文件夹结构。
src/Btn/CrudBundle/command/SystemCommand.php
:类位置
src/Btn/CrudBundle/Resources/views/email.html.twig
:模板位置
class SystemCommand extends ContainerAwareCommand
{
protected function configure()
{
$this
->setName('cron:email:send')
->setDescription('Verifies that accounts');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln("This is a test");
$message = \Swift_Message::newInstance()
->setSubject('Hello Email')
->setFrom('<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="97e4f6fae7fbf2d7e4f6fae7fbf2b9f4f8fa" rel="noreferrer noopener nofollow">[email protected]</a>')
->setTo('<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7201131f021e173201131f021e175c111d1f" rel="noreferrer noopener nofollow">[email protected]</a>')
->setBody(
$this->getContainer()->get('templating')->render(
'CrudBundle:email.html.twig',
array('name' => $staffer->getUser())
)
)
;
$this->get('mailer')->send($message);
}
}
请帮忙
最佳答案
尝试使用 CrudBundle::email.html.twig
而不是 CrudBundle:email.html.twig
。
关于templates - Symfony 加载电子邮件的 Twig 模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15542225/