安装 Sonata Dashboard 包

Posted

技术标签:

【中文标题】安装 Sonata Dashboard 包【英文标题】:Install Sonata Dashboard bundle 【发布时间】:2018-10-24 13:29:09 【问题描述】:

我想,所以我按照these 的步骤操作。

安装和配置后出现错误:

编译错误:Application\Sonata\DashboardBundle\Entity\Dashboard::getId() 的声明必须与 Sonata\DashboardBundle\Model\Dashboard::getId() 兼容:?int

我使用 Symfony 3.4、php 7.2 和 composer.json 看起来像:

"require": 
    "php": ">=5.5.9",
    "doctrine/doctrine-bundle": "^1.6",
    "doctrine/orm": "^2.5",
    "enqueue/amqp-lib": "^0.8.23",
    "friendsofsymfony/rest-bundle": "^2.3",
    "friendsofsymfony/user-bundle": "^2.1",
    "incenteev/composer-parameter-handler": "^2.0",
    "jms/serializer-bundle": "^2.3",
    "liip/monitor-bundle": "^2.6",
    "nelmio/api-doc-bundle": "^3.2",
    "sensio/distribution-bundle": "^5.0.19",
    "sensio/framework-extra-bundle": "^5.0.0",
    "sonata-project/admin-bundle": "^3.34",
    "sonata-project/block-bundle": "^3.12",
    "sonata-project/cache": "1.x-dev",
    "sonata-project/cache-bundle": "2.4",
    "sonata-project/classification-bundle": "^3.6",
    "sonata-project/core-bundle": "^3.9",
    "sonata-project/dashboard-bundle": "^0.3.0",
    "sonata-project/datagrid-bundle": "2.3",
    "sonata-project/doctrine-extensions": "^1.0",
    "sonata-project/doctrine-orm-admin-bundle": "^3.5",
    "sonata-project/easy-extends-bundle": "^2.5",
    "sonata-project/formatter-bundle": "^3.4",
    "sonata-project/google-authenticator": "^2.1",
    "sonata-project/media-bundle": "^3.12",
    "sonata-project/news-bundle": "3.4",
    "sonata-project/notification-bundle": "^3.5",
    "sonata-project/seo-bundle": "^2.5",
    "sonata-project/user-bundle": "^4.1",
    "symfony/monolog-bundle": "^3.1.0",
    "symfony/polyfill-apcu": "^1.0",
    "symfony/swiftmailer-bundle": "^2.6.4",
    "symfony/symfony": "3.4.*",
    "symfony/templating": "3.4.8",
    "twig/twig": "^1.0||^2.0"
,

有什么想法可能是错的吗?

【问题讨论】:

【参考方案1】:

看起来生成的实体错过了返回类型提示……可能是a bug in Sonata Easy Extends bundle。您可以通过查找和修改Application\Sonata\DashboardBundle\Entity\Dashboard来添加类型提示

【讨论】:

现在我将 Dashboard.php 中的函数修改为:public function getId(): ?int return $this->id;。现在一切正常,除了当我转到 URL:admin/sonata/dashboard/dashboard/create 时,它​​会引发另一个错误:类型错误:返回值 Sonata\DashboardBundle\Model\Dashboard::getEnabled() 必须是boolean 类型,返回 null 听起来像另一个错误,这里应该有一个默认值:github.com/sonata-project/SonataDashboardBundle/blob/master/src/… 您可以覆盖设置器以将其设置为您认为应该是默认值的任何值,true 或 false。

以上是关于安装 Sonata Dashboard 包的主要内容,如果未能解决你的问题,请参考以下文章

Sonata Admin Dashboard:为每个实体配置操作

Sonata 管理包模板

一些开源的dashboard 解决方案

Sonata Media Bundle 安装错误

Sonata Bundle 之间的依赖关系

Symfony 2 / Sonata / 电子商务路线问题