protected function execute(InputInterface $input, OutputInterface $output)
{
$factory = $this->getContainer()->get('sylius.factory.product');
$manager = $this->getContainer()->get('sylius.manager.product');
$product = $factory->createNew();
$product
->setName('Foo')
->setDescription('Nice product');
$manager->persist($product);
$manager->flush(); // Save changes in database.
所以我想从命令添加产品。但我总是得到这个错误:
PHP Fatal error: Call to a member function setDescription() on null in C:\Users\Coffee-Bike\IntelliJIDEAProjects\sylius-shop\acme\src\AppBundle\Command\Collmex\ImportProductsFromCollmexCommand.php on line 46
PHP Stack trace:
PHP 1. {main}() C:\Users\Coffee-Bike\IntelliJIDEAProjects\sylius-shop\acme\bin\console:0
PHP 2. Symfony\Component\Console\Application->run() C:\Users\Coffee-Bike\IntelliJIDEAProjects\sylius-shop\acme\bin\console:28
PHP 3. Symfony\Bundle\FrameworkBundle\Console\Application->doRun() C:\Users\Coffee-Bike\IntelliJIDEAProjects\sylius-shop\acme\vendor\symfony\symfony\src\Symfony\Component\Console\Application.php:130
PHP 4. Symfony\Component\Console\Application->doRun() C:\Users\Coffee-Bike\IntelliJIDEAProjects\sylius-shop\acme\vendor\symfony\symfony\src\Symfony\Bundle\FrameworkBundle\Console\Application.php:81
PHP 5. Symfony\Component\Console\Application->doRunCommand() C:\Users\Coffee-Bike\IntelliJIDEAProjects\sylius-shop\acme\vendor\symfony\symfony\src\Symfony\Component\Console\Application.php:223
PHP 6. Symfony\Component\Console\Command\Command->run() C:\Users\Coffee-Bike\IntelliJIDEAProjects\sylius-shop\acme\vendor\symfony\symfony\src\Symfony\Component\Console\Application.php:887
PHP 7. AppBundle\Command\Collmex\ImportProductsFromCollmexCommand->execute() C:\Users\Coffee-Bike\IntelliJIDEAProjects\sylius-shop\acme\vendor\symfony\symfony\src\Symfony\Component\Console\Command\Command.php:264
Fatal error: Call to a member function setDescription() on null in C:\Users\Coffee-Bike\IntelliJIDEAProjects\sylius-shop\acme\src\AppBundle\Command\Collmex\ImportProductsFromCollmexCommand.php on line 46
但是,我正在遵循此文档here。 这是同样的程序。我做错了什么?