簡體   English   中英

在Symfony2中創建命令

[英]Create command in Symfony2

我使用以下字段創建了實體用戶:名稱,密碼,電子郵件。 我真的需要創建僅提取電子郵件記錄的service嗎?( $this->getContainer()->get('myservice) )請幫我解決這個問題。

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $em = $this->getDoctrine()->getEntityManager();
        $query = $em
           ->createQuery('SELECT u.email FROM ModelBundle:User u')
        ->getResult();
        $this->getContainer()
        output->writeln($query);
    }

如果我啟動命令,則出現錯誤

[Symfony\\Component\\Debug\\Exception\\UndefinedMethodException] Attempted to call method "getDoctrine" on class "Elastica\\CoreBundle\\Comman d\\EmailCommand".

而不是$ this-> getDoctrine() ,應該使用$ this-> getContainer()-> get('doctrine')

由於$ this-> getDoctrine()快捷方式僅在控制器中可用

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM