
[英]Image Upload Issue with Symfony3, Doctrine 2 and Sonata Admin Bundle
[英]Using Doctrine Uuid type with Sonata Admin Bundle for Symfony
我无法让 Sonata Admin Bundle 使用 Ramsey 的 Uuid 作为实体的 ID。
这是我尝试显示国家/地区列表 (/admins/app/country/list) 时遇到的错误
在渲染模板期间抛出异常(“请求的未知数据库类型 uuid,Doctrine\DBAL\Platforms\MySQL57Platform 可能不支持它。”)。
doctrine.yaml
doctrine:
dbal:
types:
uuid: Ramsey\Uuid\Doctrine\UuidType
服务.yaml
sonata.admin.country:
class: App\Admin\CountryAdmin
arguments: [~, App\Entity\Country, ~]
tags:
- { name: sonata.admin, manager_type: orm, group: Entities, label: 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()));
}
}
应用\控制器\管理员\国家控制器
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,
]);
}
}
作曲家.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 类型,尽管它位于 doctrine.yaml 配置文件中。 我尝试将其手动包含在 bootstrap.php 中:
\Doctrine\DBAL\Types\Type::addType('uuid', 'Ramsey\Uuid\Doctrine\UuidType');
但我只是收到一条错误消息,说明该类型已包含在内。
我意识到vendor/sonata-project/doctrine-extensions/src/Types
只包含 JsonType.php。 会不会是 Uuid.php 不见了? 还是我错过了其他东西? 谢谢您的帮助 !
我终于找到了这个问题的答案。 我所要做的就是将 2 行添加到doctrine.yaml文件中:
doctrine:
dbal:
types:
uuid: Ramsey\Uuid\Doctrine\UuidType
mapping_types: <---
uuid: uuid <---
我希望它可以帮助某人,因为我个人无法在互联网上的任何地方找到信息!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.