'Not able to access model in the controller mautic

Not able to access new model in the controller in mautic

Mautic uses Symfony 2.x framework

Steps taken:

  • created entity extending CommonEntity
  • created repository extending CommonRepository
  • created model extending FormModel

Registered services in the config

'repositories' => [
            'mautic.campaignrequest.repository.campaignrequest' => [
                'class'     => Doctrine\ORM\EntityRepository::class,
                'factory'   => ['@doctrine.orm.entity_manager', 'getRepository'],
                'arguments' => [
                    \Mautic\CampaignRequestBundle\Entity\CampaignRequest::class,
                ],



'models'     => [
            'mautic.campaignrequest.model.campaignrequest'  => [
                'class'       => \Mautic\CampaignRequestBundle\Model\CampaignRequestModel::class,
                'arguments'   => [],
            ],

But when tried to access the model in the controller it throws an error saying model is not registered in the container. Am I missing something??, could someone please help me out.

The error says:

[2019-12-23 13:23:47] mautic.CRITICAL: Uncaught PHP Exception InvalidArgumentException: "mautic.campaignrequest.model.campaignrequest is not a registered container key." at /projects/mautic/2.15.2/mautic/app/bundles/ApiBundle/Controller/CommonApiController.php line 923 {"exception":"[object] (InvalidArgumentException(code: 0): mautic.campaignrequest.model.campaignrequest is not a registered container key. at /projects/mautic/2.15.2/mautic/app/bundles/ApiBundle/Controller/CommonApiController.php:923)"} []



Solution 1:[1]

'mautic.campaignrequest.model.campaignrequest'  => [
                'class'       => \Mautic\CampaignRequestBundle\Model\CampaignRequestModel::class,
                'arguments'   => [],
            ],

You should use MauticPlugin instead of Mautic in class as your bundle exist in the plugins folder

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Suraj Rao