Doctrine orm 将Uuid类型与Sonata管理包一起用于Symfony
我很难让Sonata管理包使用Ramsey的Uuid作为实体Id 这是我尝试显示国家/地区列表时遇到的错误(/admins/app/Country/list) 在呈现模板期间引发了异常(“请求了未知的数据库类型uuid,Doctrine\DBAL\Platforms\MySQL57Platform可能不支持它”) 教义。yamlDoctrine orm 将Uuid类型与Sonata管理包一起用于Symfony,doctrine-orm,symfony4,uuid,sonata-admin,Doctrine Orm,Symfony4,Uuid,Sonata Admin,我很难让Sonata管理包使用Ramsey的Uuid作为实体Id 这是我尝试显示国家/地区列表时遇到的错误(/admins/app/Country/list) 在呈现模板期间引发了异常(“请求了未知的数据库类型uuid,Doctrine\DBAL\Platforms\MySQL57Platform可能不支持它”) 教义。yaml doctrine: dbal: types: uuid: Ramsey\Uuid\Doctrine\UuidType
doctrine:
dbal:
types:
uuid: Ramsey\Uuid\Doctrine\UuidType
sonata.admin.country:
class: App\Admin\CountryAdmin
arguments: [~, App\Entity\Country, ~]
tags:
- { name: sonata.admin, manager_type: orm, group: Entities, label: Country }
服务。yaml
doctrine:
dbal:
types:
uuid: Ramsey\Uuid\Doctrine\UuidType
sonata.admin.country:
class: App\Admin\CountryAdmin
arguments: [~, App\Entity\Country, ~]
tags:
- { name: sonata.admin, manager_type: orm, group: Entities, label: Country }
App\Entity\Country
class Country
{
/**
* @ORM\Id
* @ORM\Column(type="uuid", unique=true)
* @ORM\GeneratedValue(strategy="CUSTOM")
* @ORM\CustomIdGenerator(class="Ramsey\Uuid\Doctrine\UuidGenerator")
*/
protected $id;
final class CountryAdmin extends Sonata\AdminBundle\Admin\AbstractAdmin
{
protected function configureRoutes(RouteCollection $collection)
{
$collection
->add('show_country', sprintf('%s/show_country', $this->getRouterIdParameter()));
}
}
App\Admin\Country
class Country
{
/**
* @ORM\Id
* @ORM\Column(type="uuid", unique=true)
* @ORM\GeneratedValue(strategy="CUSTOM")
* @ORM\CustomIdGenerator(class="Ramsey\Uuid\Doctrine\UuidGenerator")
*/
protected $id;
final class CountryAdmin extends Sonata\AdminBundle\Admin\AbstractAdmin
{
protected function configureRoutes(RouteCollection $collection)
{
$collection
->add('show_country', sprintf('%s/show_country', $this->getRouterIdParameter()));
}
}
App\Controller\Admin\CountryController
class CountryController extends Sonata\AdminBundle\Controller\CRUDController
{
public function showCityAction(Request $request): Response
{
/** @var Country $country */
$country = $this->admin->getSubject();
if (!$country) {
$id = $request->get($this->admin->getIdParameter());
throw $this->createNotFoundException(sprintf(
'Unable to find the object with id : %s',
$id
));
}
return $this->renderWithExtraParams('admin/city/show_country.html.twig', [
'show_country' => $country,
]);
}
}
composer.json
"sonata-project/admin-bundle": "^3.53",
"sonata-project/doctrine-orm-admin-bundle": "^3.10",
"sonata-project/translation-bundle": "^2.4",
"sonata-project/user-bundle": "^4.4",
"stof/doctrine-extensions-bundle": "^1.3",
"sonata-project/easy-extends-bundle": "^2.5",
"ramsey/uuid-doctrine": "^1.5"
虽然Uuid类型在doctor.yaml配置文件中,但似乎没有加载。我尝试将其手动包含在bootstrap.php中:
\doctor\DBAL\Types\Type::addType('uuid','Ramsey\uuid\doctor\UuidType')代码>
但是我刚刚收到一条错误消息,说类型已经包括在内了
我意识到vendor/sonata project/doctrine extensions/src/Types
只包含JsonType.php。可能是Uuid.php丢失了吗?还是我错过了什么?谢谢你的帮助 我终于找到了答案。我所要做的就是将这两行代码添加到doctrine.yaml文件中:
doctrine:
dbal:
types:
uuid: Ramsey\Uuid\Doctrine\UuidType
mapping_types: <---
uuid: uuid <---
原则:
dbal:
类型:
uuid:Ramsey\uuid\Doctrine\UuidType
映射类型:在composer.json中没有“ramsey/uuid原则”
的条目?有,我把它添加到了我的问题中。Uuid在应用程序中运行良好,是sonata管理员让我得到了错误。。。