我收到此错误
无法访问空属性
当我尝试此命令时abc:check-car
<?php
namespace CarBundle\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class AbcCheckCarCommand extends Command
{
protected $carChecker;
protected $manager;
/**
* AbcCheckCarCommand constructor.
* @param $carChecker
* @param $manager
*/
public function __construct($carChecker, $manager)
{
$this->carChecker = $carChecker;
$this->manager = $manager;
parent::__construct();
}
protected function configure()
{
$this
->setName('abc:check-car')
->setDescription('...')
->addArgument('format', InputArgument::OPTIONAL, 'format progress bar')
->addOption('option', null, InputOption::VALUE_NONE, 'Option description')
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$carRepository = $this->$manager->getRepository('CarBundle:Car');
$cars = $carRepository->findAll();
$bar = new ProgressBar($output, count($cars));
$argument = $input->getArgument('format');
$bar->setFormat($argument);
$bar->start();
foreach ($cars as $car)
{
$this->carChecker->checkCar($car);
sleep(1);
$bar->advance();
}
$bar->finish();
}
}
答案 0 :(得分:1)
变化
$carRepository = $this->$manager->getRepository('CarBundle:Car');
到
$carRepository = $this->manager->getRepository('CarBundle:Car');
在经理面前记住$