Search code examples
zend-frameworkdoctrine-ormdoctrinezend-framework3doctrine-query

How to add functions in entity manager configuration doctrine in zend framework 3


I have currently a controller and a controller factory

AbcControllerFactory

public function __invoke(ContainerInterface $container, $requestedName, array $options = null){
    $entityManager                   =  $container->get("doctrine.entitymanager.orm_default");
    return new AbcController($entityManager);
}

And AbcController

private $entityManager;
public function __construct($entityManager){
    $this->entityManager             =  $entityManager;
}

I am trying to use this doctrine library

doctrine library for json functions

but the only issue is I'm stuck in adding these functions

$config = new \Doctrine\ORM\Configuration();
$config->addCustomStringFunction(DqlFunctions\JsonExtract::FUNCTION_NAME, DqlFunctions\JsonExtract::class);
$config->addCustomStringFunction(DqlFunctions\JsonSearch::FUNCTION_NAME, DqlFunctions\JsonSearch::class);

I'm fairly new to this doctrine bit. Can anyone help how should I add these function in the existing entity manager configuration

This is my local.php file where all information is stored

return [
"doctrine" => [
    "connection" => [
        "orm_default" => [
            "driverClass" => PDOMySqlDriver::class,
            "params" => [
                "driver"             => "pdo_mysql",
                "dsn"                => "mysql:dbname=abc;host=localhost;charset=utf8",
                "host"     => "localhost",
                "user"     => "root",
                "password" => "",
                "dbname"   => "abc",
            ]
        ],
    ],
],

];


Solution

  • Okay this is a bit sluggish from me. However, I found out you could add function like this in controller:

    $this->entityManager->getConfiguration()->addCustomStringFunction(DqlFunctions\JsonExtract::FUNCTION_NAME, DqlFunctions\JsonExtract::class);
    $this->entityManager->getConfiguration()->addCustomStringFunction(DqlFunctions\JsonSearch::FUNCTION_NAME, DqlFunctions\JsonSearch::class);