【问题标题】:Use Doctrine with REST APIs将 Doctrine 与 REST API 一起使用
【发布时间】:2016-07-16 00:28:48
【问题描述】:

是否可以使用 REST API 作为 Doctrine 数据库?

关于http://doctrine-orm.readthedocs.org/projects/doctrine-dbal/en/latest/reference/configuration.html上的配置,我可以更改“驱动程序”属性。

但在允许的驱动程序列表中,没有人使用 REST API。

我想做的是:

<?php
$config = new \Doctrine\DBAL\Configuration();
//..
$connectionParams = array(
    'dbname' => 'my_rest_api',
    'user' => 'user',
    'password' => 'secret',
    'host' => 'localhost:3000',
    'driver' => 'rest',
);
$conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config);

$entityManager = EntityManager::create($conn, $config);

// Sends a GET request to localhost:3000/myentity/1 and maps it properly to my configured entity
$entity = $entityManager->find("MyNamespace\Entity\MyEntity", 1);

// Sends a POST request to localhost:3000/myentity
$entity = new MyEntity();
$entityManager->persist($entity);
$entityManager->flush();

// and so on

感谢您的回答!!

【问题讨论】:

    标签: rest symfony doctrine driver dbal


    【解决方案1】:

    DoctrineRestDriver 正在做你正在寻找的东西!

    https://github.com/CircleOfNice/DoctrineRestDriver

    玩得开心!

    【讨论】:

      猜你喜欢
      • 2014-02-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多