【发布时间】:2017-08-07 17:16:12
【问题描述】:
我正在使用 symfony 2 命令类构建一个批处理文件。我有一个函数可以从包中的控制器处理 DB
class SubmitDisclosureController extends FOSRestController implements MEAuthController
{
...
public function discDetails($discId) {
$emr = $this->getDoctrine()->getEntityManager();
我从命令src/AppBundle/Command/BatchJobCommand.php
调用它,如下所示
class BatchJobCommand extends Command
{
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln([
'User Creator',
'============',
'',
]);
// retrieve the argument value using getArgument()
$output->writeln('First batch job')
$disc = new SubmitDisclosureController();
$disc->discDetails('42094');
`
如果我尝试执行它,它会给出PHP Fatal error: Call to a member function has() on null in C:\xampp\htdocs\GR\
vendor\symfony\symfony\src\Symfony\Bundle\FrameworkBundle\Controller\Controller.
php on line 288
难道不能通过从命令类调用控制器的功能来重用代码吗?
【问题讨论】:
-
其实你需要的其实是一个控制器和命令都可以使用的服务
-
@MateiMihai 是的,你是对的。但这种变化会影响现有的功能。
标签: php symfony command-line-interface symfony-2.6