我目前有一个控制器和一个控制器工厂
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",
]
],
],
],
];
好吧,这是从我有点呆滞。然而,我发现,你可以在控制器添加功能如下:
$this->entityManager->getConfiguration()->addCustomStringFunction(DqlFunctions\JsonExtract::FUNCTION_NAME, DqlFunctions\JsonExtract::class);
$this->entityManager->getConfiguration()->addCustomStringFunction(DqlFunctions\JsonSearch::FUNCTION_NAME, DqlFunctions\JsonSearch::class);