如何在Zend Framework 3中的实体管理器配置原则中添加功能

时间:2019-02-08 16:38:35

标签: zend-framework doctrine-orm doctrine zend-framework3 doctrine-query

我目前有一个控制器和一个控制器工厂

AbcControllerFactory

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

和AbcController

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

我正在尝试使用该学说库

doctrine library for json functions

但是唯一的问题是我被困在添加这些功能中

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

我对这个学说有点陌生。谁能帮助我该如何在现有的实体管理器配置中添加这些功能

这是我存储所有信息的local.php文件

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",
            ]
        ],
    ],
],

];

1 个答案:

答案 0 :(得分:0)

好吧,这对我来说有点迟钝。但是,我发现您可以在控制器中添加如下功能:

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