2013-03-21 63 views
2

我在加載過程中遇到了symfony樹枝模板的錯誤。Symfony加載樹枝電子郵件模板

我需要包括:使用Sensio \ Bundle \ FrameworkExtraBundle \ Configuration \ Template;

[InvalidArgumentException]

Unable to find template "CrudBundle:email.html.twig".

[Twig_Error_Loader]

Unable to find template "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('[email protected]') 
      ->setTo('[email protected]') 
      ->setBody(
       $this->getContainer()->get('templating')->render(
        'CrudBundle:email.html.twig', 
        array('name' => $staffer->getUser()) 
       ) 
      ) 
     ; 
     $this->get('mailer')->send($message);   
    } 
} 

請幫

+4

看起來你忘了給模板名添加第二個冒號。 CrudBundle :: email.html.twig。你也可以簡單地使用$ this-> render來代替$ this-> getContainer() - > get('templating') - > render – 2013-03-21 08:20:13

回答

2

嘗試CrudBundle::email.html.twig代替CrudBundle:email.html.twig