无法在空变量上访问属性(" flashBag")

时间:2018-02-08 19:15:51

标签: php symfony twig

我在服务symfony 3.3中使用模板时出现此错误..我已发送电子邮件..我使用控制台命令来使用服务..在文件树枝中我做过'使用flashBag ..我使用简单的文本。 。在twig中的代码永远不会用户flashbag或其他代码

enter image description here

code services.yml:

add_id_context:
    class: Context\ContextBundle\Services\ContextService
    arguments: [ "@doctrine.orm.entity_manager" ]
    public: true         

代码服务:

    namespace Context\ContextBundle\Services;

    use ContextIO;
    use Doctrine\ORM\EntityManagerInterface;
    use AppBundle\Entity\Recruiter;
    use Symfony\Component\DependencyInjection\ContainerInterface;

    Class ContextService 
    {

        /**
         * @var EntityManagerInterface
         */
        private $em;

        /**
         * @var \Swift_Mailer
         */
        private $mailer;

        /**
         * @var ContainerInterface
         */
        private $container;


         /**
         * construct ContextService.
         *
         * @param EntityManagerInterface $em
         *
         * @param \Swift_Mailer $mailer
         *
         * @param ContainerInterface $container
         */
        public function __construct(EntityManagerInterface $em, \Swift_Mailer $mailer, ContainerInterface $container)
        {
            $this->em = $em;
            $this->mailer = $mailer;
            $this->container = $container;
        }

        /**
         * function AddIdContext
         */
        public function AddIdContext()
        {


                                    $message = \Swift_Message::newInstance()
                            ->setSubject('test validate')
                            ->setFrom('test@gmail.com')
                            ->setTo('test@gmail.com')
                    ->setBody($this->container->get('templating')->render('AppBundle:PublicController/Contextio:validateUser.html.twig'));
                            $this->mailer->send($message);


        } // end function
    }

console commande:

<?php 

    namespace AppBundle\Command;

    use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
    use Symfony\Component\Console\Output\OutputInterface;
    use Symfony\Component\Console\Input\InputInterface;

    /**
     * Class ContextCommand
     */

    Class ContextCommand extends ContainerAwareCommand
    {
        /**
         * {@inheritdoc}
         */
        protected function configure()
        {
            $this
                ->setName('recurit:add:context')
                ->setDescription('Add account context.');
        }

        /**
         * {@inheritdoc}
         */
        protected function execute(InputInterface $input, OutputInterface $output)
        {
            $contextService = $this->getContainer()->get('add_id_context');
            $contextService->AddIdContext();
            $output->writeln(sprintf('successs'));
        }
    }

并提交validateUser.html.twig内容:

test send mail

如何解决此错误!!

0 个答案:

没有答案