【发布时间】:2013-10-19 17:56:24
【问题描述】:
我是 Symfony 的新手。我创建了一个自定义命令,其唯一目的是从系统中擦除演示数据,但我不知道如何执行此操作。
在控制器中我会这样做:
$nodes = $this->getDoctrine()
->getRepository('MyFreelancerPortfolioBundle:TreeNode')
->findAll();
$em = $this->getDoctrine()->getManager();
foreach($nodes as $node)
{
$em->remove($node);
}
$em->flush();
从我得到的命令中的 execute() 函数执行此操作:
Call to undefined method ..... ::getDoctrine();
如何通过 execute() 函数执行此操作?此外,如果有更简单的方法来擦除数据而不是循环遍历它们并删除它们,请随时提及。
【问题讨论】:
标签: php symfony console command