当我想将学说实体与 API 平台注释分开时,我有一个案例。主要问题是我能够创建一个资源,看起来还可以,但它没有保存在数据库中。似乎我需要再添加一件事,但不知道在这里放什么。
映射是正确的,数据库是最新的......
实体类:
<?php
declare(strict_types=1);
namespace Entity;
use Ramsey\Uuid\UuidInterface;
class Example
{
/**
* @var UuidInterface
*/
protected $uuid;
/**
* @var string
*/
protected $name;
}
实体映射:
<doctrine-mapping
xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping https://raw.github.com/doctrine/doctrine2/master/doctrine-mapping.xsd"
>
<entity name="Entity\Example" table="examples">
<id name="uuid" type="uuid" column="uuid" />
<field name="name" type="string" column="name" />
</entity>
</doctrine-mapping>
Api 平台类
<?php
declare(strict_types=1);
namespace ApiPlatform;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use Entity\Example as EntityExample;
use Ramsey\Uuid\UuidInterface;
/**
* @ApiResource()
*/
class Example extends EntityExample
{
/**
* @ApiProperty(identifier=true)
* @var UuidInterface
*/
protected $uuid;
/**
* @return UuidInterface
*/
public function getUuid() : UuidInterface
{
return $this->uuid;
}
/**
* @return string
*/
public function getName() : string
{
return $this->name;
}
/**
* @param UuidInterface $uuid
*/
public function setUuid(UuidInterface $uuid) : void
{
$this->uuid = $uuid;
}
/**
* @param string $name
*/
public function setName(string $name) : void
{
$this->name = $name;
}
}
茅侃侃
慕尼黑5688855