Closed grekpg closed 3 years ago
Hi @grekpg , exception happens in line 55
in BaseImportControllerTrait
?
Validator is injected using CompilerPass for every service with tag batch_entity_import.controller
. This tag should be automatically added for every class which implements ImportControllerInterface
. I think that it is not working properly for custom controllers.
As temporary fix you can add tag to your controller:
Your\Namespace\CentroShopAdminCRUDController:
tags: [ 'batch_entity_import.controller' ]
Let me know if this temporary fix works.
I will check it next week and try to fix it.
@grekpg can you check if you have autoconfiguration for your services turned on?
services:
_defaults:
public: true
autowire: true
autoconfigure: true
You can turn it on, or just use the solution from previous post.
Hi @grekpg , exception happens in line
55
inBaseImportControllerTrait
?Validator is injected using CompilerPass for every service with tag
batch_entity_import.controller
. This tag should be automatically added for every class which implementsImportControllerInterface
. I think that it is not working properly for custom controllers.As temporary fix you can add tag to your controller:
Your\Namespace\CentroShopAdminCRUDController: tags: [ 'batch_entity_import.controller' ]
Let me know if this temporary fix works.
I will check it next week and try to fix it.
When i add
app.admin.controller.centro_shop_admin_crudcontroller:
class: App\Admin\Controller\CentroShopAdminCRUDController
public: true
autowire: true
autoconfigure: true
tags:
- { name: controller.service_arguments }
- { name: batch_entity_import.controller }
error was gone but i get
JG\BatchEntityImportBundle\Model\Configuration\AbstractImportConfiguration::__construct(): Argument #1 ($em) must be of type Doctrine\ORM\EntityManagerInterface, null given, called in /application/vendor/jgrygierek/batch-entity-import-bundle/src/Controller/BaseImportControllerTrait.php on line 130
i add
App\ImportConfiguration\:
resource: '../src/ImportConfiguration/'
tags: [ 'controller.service_arguments' ]
public: true
autowire: true
autoconfigure: true
import configuration class is
class CentroShopImport extends AbstractImportConfiguration
{
public function getEntityClassName(): string
{
return CentroShop::class;
}
}
@grekpg I think you don't need to add import configuration class as a service.
1) If your controller has tag batch_entity_import.controller
, entity manager is injected into this controller
2) Inside controller entity manager is injected manually into constructor of import configuration, not via autowiring.
Can you tell me what is value of $this->em
inside your controller, before this error happens in line 130?
@grekpg I think you don't need to add import configuration class as a service.
- If your controller has tag
batch_entity_import.controller
, entity manager is injected into this controller- Inside controller entity manager is injected manually into constructor of import configuration, not via autowiring.
Can you tell me what is value of
$this->em
inside your controller, before this error happens in line 130?
i override
$this->em is null. so i override this method in my crud controller: get $this->getDoctrine()->getManager() not $this->em
protected function getImportConfiguration(): ImportConfigurationInterface
{
$this->checkDI();
if (!$this->importConfiguration) {
$class = $this->getImportConfigurationClassName();
if (!class_exists($class)) {
throw new UnexpectedValueException('Configuration class not found.');
}
$this->importConfiguration = new $class($this->getDoctrine()->getManager());
}
return $this->importConfiguration;
}
and now its work :)
em
should have a value, it is injected in the same time like validator
using tag. So maybe you have something in your custom controller which is blocking injecting data?
em
should have a value, it is injected in the same time likevalidator
using tag. So maybe you have something in your custom controller which is blocking injecting data?
yes it possible, but for my it can work like now. But i think - why inject em -> sonata crud controller has it so you can take without create injection.
Yes, but I use here my another package, which is built for Symfony, not Sonata.
But you are right, this package should use getDoctrine
method. I will change it.
admin config
controller
where can be a problem ?
ps. thanks for great bundle...