Symfony2 命令和 tcpdf whiteoctober
Symfony2 command and tcpdf whiteoctober
我使用 symfony 并成功安装了 whiteoctober TCPDF。
如果我在控制器中使用它,它会工作,生成我的 PDF。
但是我想在命令中使用它。
所以我在命令文件夹中有一个名为 "CronInvoicesCommand" 的命令,当然我有这个错误:
Attempted to call method "get" on class "OandP\boBundle\Command\CronInvoicesCommand" in C:\wamp\www\OandPlocal\src\OandP\boBundle\Command\CronInvoicesCommand.php line 187. Did you mean to call: "getAliases", "getApplication", "getDefinition", "getDescription", "getHelp", "getHelper", "getHelperSet", "getName", "getNativeDefinition", "getProcessedHelp", "getSynopsis"?
所以我的问题是如何在命令中加载所有这些方法。
非常感谢您的帮助
可能您正在尝试从类似于控制器方法 get 的容器中获取服务。在命令中,您可以使用 getContainer() 方法访问容器,因此请尝试替换为:
$this->get('service_name');
和
$this->getContainer()->get('service_name');
更多信息here in the doc。
希望对您有所帮助
您可以使用容器感知命令:
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
class MyCommand extends ContainerAwareCommand
{
protected function execute(InputInterface $input, OutputInterface $output)
{
$em = $this->getContainer()->get('doctrine')->getEntityManager();
// ...
我使用 symfony 并成功安装了 whiteoctober TCPDF。 如果我在控制器中使用它,它会工作,生成我的 PDF。
但是我想在命令中使用它。 所以我在命令文件夹中有一个名为 "CronInvoicesCommand" 的命令,当然我有这个错误:
Attempted to call method "get" on class "OandP\boBundle\Command\CronInvoicesCommand" in C:\wamp\www\OandPlocal\src\OandP\boBundle\Command\CronInvoicesCommand.php line 187. Did you mean to call: "getAliases", "getApplication", "getDefinition", "getDescription", "getHelp", "getHelper", "getHelperSet", "getName", "getNativeDefinition", "getProcessedHelp", "getSynopsis"?
所以我的问题是如何在命令中加载所有这些方法。 非常感谢您的帮助
可能您正在尝试从类似于控制器方法 get 的容器中获取服务。在命令中,您可以使用 getContainer() 方法访问容器,因此请尝试替换为:
$this->get('service_name');
和
$this->getContainer()->get('service_name');
更多信息here in the doc。
希望对您有所帮助
您可以使用容器感知命令:
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
class MyCommand extends ContainerAwareCommand
{
protected function execute(InputInterface $input, OutputInterface $output)
{
$em = $this->getContainer()->get('doctrine')->getEntityManager();
// ...