sonata-project / SonataAdminBundle

The missing Symfony Admin Generator
https://docs.sonata-project.org/projects/SonataAdminBundle
MIT License
2.1k stars 1.26k forks source link

No entity manager defined for class #8182

Closed gekomod closed 2 months ago

gekomod commented 2 months ago

Hello, I have a problem, I wrote a bundle, I don't have an Entity without a database, and unfortunately I have this error: there was no error on the previous version of symfony and sonata admin clean new installation Symfony 6, php8

No entity manager defined for class Gekomod\ExtensionsBundle\Admin\ExtensionsAdmin

<?php

namespace Gekomod\ExtensionsBundle\Admin;

use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Route\RouteCollection;

class ExtensionsAdmin extends AbstractAdmin {
    protected $baseRoutePattern = 'extensions';
    protected $baseRouteName = 'extensions';

    protected function configureRoutes(\Sonata\AdminBundle\Route\RouteCollectionInterface
$collection): void
    {
        $collection->clearExcept(['list']);
        $collection->add('install', 'install/{name}', [], [], [], '', ['http','https'], ['GET']);
        $collection->add('uninstall', 'uninstall/{name}', [], [], [], '', ['http','https'], ['GET']);
        $collection->add('upgrade', 'upgrade/{name}', [], [], [], '', ['http','https'], ['GET']);
        $collection->add('search', 'search/{name}', [], [], [], '', ['http','https'], ['GET']);
    }
}

services.yaml

services:
    _defaults: { public: false, autowire: true, autoconfigure: true }
    Gekomod\ExtensionsBundle\Controller\:
        resource: '%kernel.project_dir%/vendor/gekomod/extensions-bundle/Controller'
        autowire: true
        tags: ['controller.service_arguments']
    admin.extensions:
        class: Gekomod\ExtensionsBundle\Admin\ExtensionsAdmin
        tags:
            - { name:  sonata.admin, manager_type: orm, model_class: Gekomod\ExtensionsBundle\Admin\ExtensionsAdmin, translation_domain: 'App', group: 'Usta$
        arguments:
            - null
            - null
            - Gekomod\ExtensionsBundle\Controller\ExtensionsCRUDController
        public: true
VincentLanglet commented 2 months ago

I don't have an Entity without a database

What do you mean ?

and unfortunately I have this error:

Do you have a stack trace ?

there was no error on the previous version of symfony and sonata admin

Which version ?

gekomod commented 2 months ago
RuntimeException:
No entity manager defined for class Gekomod\ExtensionsBundle\Admin\ExtensionsAdmin

  at vendor/sonata-project/doctrine-orm-admin-bundle/src/Model/ModelManager.php:192
  at Sonata\DoctrineORMAdminBundle\Model\ModelManager->getEntityManager('Gekomod\\ExtensionsBundle\\Admin\\ExtensionsAdmin')
     (vendor/sonata-project/doctrine-orm-admin-bundle/src/Model/ModelManager.php:203)
  at Sonata\DoctrineORMAdminBundle\Model\ModelManager->createQuery('Gekomod\\ExtensionsBundle\\Admin\\ExtensionsAdmin')
     (vendor/sonata-project/admin-bundle/src/Admin/AbstractAdmin.php:893)
  at Sonata\AdminBundle\Admin\AbstractAdmin->createQuery()
     (vendor/sonata-project/doctrine-orm-admin-bundle/src/Builder/DatagridBuilder.php:156)
  at Sonata\DoctrineORMAdminBundle\Builder\DatagridBuilder->getBaseDatagrid(object(ExtensionsAdmin), array('_page' => 1, '_per_page' => 25))
     (vendor/sonata-project/admin-bundle/src/Admin/AbstractAdmin.php:2421)
  at Sonata\AdminBundle\Admin\AbstractAdmin->buildDatagrid()
     (vendor/sonata-project/admin-bundle/src/Admin/AbstractAdmin.php:905)
  at Sonata\AdminBundle\Admin\AbstractAdmin->getDatagrid()
     (vendor/sonata-project/admin-bundle/src/Controller/CRUDController.php:126)
  at Sonata\AdminBundle\Controller\CRUDController->listAction(object(Request))
     (vendor/symfony/http-kernel/HttpKernel.php:163)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
     (vendor/symfony/http-kernel/HttpKernel.php:75)
  at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
     (vendor/symfony/http-kernel/Kernel.php:202)
  at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
     (vendor/symfony/runtime/Runner/Symfony/HttpKernelRunner.php:35)
  at Symfony\Component\Runtime\Runner\Symfony\HttpKernelRunner->run()
     (vendor/autoload_runtime.php:29)
  at require_once('/home/klient.dhosting.pl/zaba141/vwcoding.pl/public_html/vendor/autoload_runtime.php')
     (public/index.php:5)                
doctrine/annotations                     2.0.1   Docblock Annotations Parser
doctrine/cache                           2.2.0   PHP Doctrine Cache library is a popular cache implementation that supports many different drivers such ...
doctrine/collections                     1.8.0   PHP Doctrine Collections library that adds additional functionality on top of PHP arrays.
doctrine/common                          3.4.4   PHP Doctrine Common project is a library that provides additional functionality that other Doctrine pro...
doctrine/dbal                            3.8.4   Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and...
doctrine/deprecations                    1.1.3   A small layer on top of trigger_error(E_USER_DEPRECATED) or PSR-3 logging with options to disable all d...
doctrine/doctrine-bundle                 2.12.0  Symfony DoctrineBundle
doctrine/doctrine-migrations-bundle      3.3.0   Symfony DoctrineMigrationsBundle
doctrine/event-manager                   1.2.0   The Doctrine Event Manager is a simple PHP event system that was built to be used with the various Doct...
doctrine/inflector                       2.0.10  PHP Doctrine Inflector is a small library that can perform string manipulations with regard to upper/lo...
doctrine/instantiator                    1.5.0   A small, lightweight utility to instantiate objects in PHP without invoking their constructors
doctrine/lexer                           2.1.1   PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers.
doctrine/migrations                      3.5.5   PHP Doctrine Migrations project offer additional functionality on top of the database abstraction layer...
doctrine/orm                             2.19.5  Object-Relational-Mapper for PHP
doctrine/persistence                     3.3.2   The Doctrine Persistence project is a set of shared interfaces and functionality that the different Doc...
doctrine/sql-formatter                   1.2.0   a PHP SQL highlighting library
egulias/email-validator                  3.2.6   A library for validating emails against several RFCs
friendsofphp/proxy-manager-lts           v1.0.18 Adding support for a wider range of PHP versions to ocramius/proxy-manager
gekomod/extensions-bundle                1.2     Symfony Gekomod/ExtensionsBundle
guzzlehttp/guzzle                        7.8.1   Guzzle is a PHP HTTP client library
guzzlehttp/promises                      2.0.2   Guzzle promises library
guzzlehttp/psr7                          2.6.2   PSR-7 message implementation that also provides common utility methods
jms/metadata                             2.8.0   Class/method/property metadata management in PHP
jms/serializer                           3.30.0  Library for (de-)serializing data of any complexity; supports XML, and JSON.
knplabs/knp-menu                         v3.4.0  An object oriented menu library
knplabs/knp-menu-bundle                  v3.2.0  This bundle provides an integration of the KnpMenu library
knplabs/packagist-api                    v1.7.2  Packagist API client.
laminas/laminas-code                     4.7.1   Extensions to the PHP Reflection API, static code scanning, and code generation
nikic/php-parser                         v4.19.1 A PHP parser written in PHP
phpstan/phpdoc-parser                    1.28.0  PHPDoc parser with support for nullable, intersection and generic types
psr/cache                                3.0.0   Common interface for caching libraries
psr/container                            2.0.2   Common Container Interface (PHP FIG PSR-11)
psr/event-dispatcher                     1.0.0   Standard interfaces for event handling.
psr/http-client                          1.0.3   Common interface for HTTP clients
psr/http-factory                         1.0.2   Common interfaces for PSR-7 HTTP message factories
psr/http-message                         2.0     Common interface for HTTP messages
psr/log                                  3.0.0   Common interface for logging libraries
ralouphie/getallheaders                  3.0.3   A polyfill for getallheaders.
sonata-project/admin-bundle              4.22.4  The missing Symfony Admin Generator
sonata-project/block-bundle              4.19.0  Symfony SonataBlockBundle
sonata-project/cache                     2.2.0   Cache library
sonata-project/doctrine-extensions       2.4.0   Doctrine2 behavioral extensions
sonata-project/doctrine-orm-admin-bundle 4.9.1   Integrate Doctrine ORM into the SonataAdminBundle
sonata-project/exporter                  3.3.0   Lightweight Exporter library
sonata-project/form-extensions           1.18.0  Symfony form extensions
sonata-project/twig-extensions           2.0.0   Sonata twig extensions
sonata-project/user-bundle               5.5.0   Symfony SonataUserBundle
symfony/acl-bundle                       v2.4.0  Symfony AclBundle
symfony/asset                            v6.0.19 Manages URL generation and versioning of web assets such as CSS stylesheets, JavaScript files and image...
symfony/cache                            v6.0.19 Provides extended PSR-6, PSR-16 (and tags) implementations
symfony/cache-contracts                  v3.0.2  Generic abstractions related to caching
symfony/config                           v6.0.19 Helps you find, load, combine, autofill and validate configuration values of any kind
symfony/console                          v6.0.19 Eases the creation of beautiful and testable command line interfaces
symfony/dependency-injection             v6.0.20 Allows you to standardize and centralize the way objects are constructed in your application
symfony/deprecation-contracts            v3.0.2  A generic function and convention to trigger deprecation notices
symfony/doctrine-bridge                  v6.0.19 Provides integration for Doctrine with various Symfony components
symfony/dotenv                           v6.0.19 Registers environment variables from a .env file
symfony/error-handler                    v6.0.19 Provides tools to manage errors and ease debugging PHP code
symfony/event-dispatcher                 v6.0.19 Provides tools that allow your application components to communicate with each other by dispatching eve...
symfony/event-dispatcher-contracts       v3.0.2  Generic abstractions related to dispatching event
symfony/expression-language              v6.0.19 Provides an engine that can compile and evaluate expressions
symfony/filesystem                       v6.0.19 Provides basic utilities for the filesystem
symfony/finder                           v6.0.19 Finds files and directories via an intuitive fluent interface
symfony/flex                             v2.4.5  Composer plugin for Symfony
symfony/form                             v6.0.19 Allows to easily create, process and reuse HTML forms
symfony/framework-bundle                 v6.0.19 Provides a tight integration between Symfony components and the Symfony full-stack framework
symfony/http-foundation                  v6.0.20 Defines an object-oriented layer for the HTTP specification
symfony/http-kernel                      v6.0.20 Provides a structured process for converting a Request into a Response
symfony/mailer                           v6.0.19 Helps sending emails
symfony/maker-bundle                     v1.50.0 Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can for...
symfony/mime                             v6.0.19 Allows manipulating MIME messages
symfony/options-resolver                 v6.0.19 Provides an improved replacement for the array_replace PHP function
symfony/password-hasher                  v6.0.19 Provides password hashing utilities
symfony/polyfill-intl-grapheme           v1.29.0 Symfony polyfill for intl's grapheme_* functions
symfony/polyfill-intl-icu                v1.29.0 Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-intl-idn                v1.29.0 Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions
symfony/polyfill-intl-normalizer         v1.29.0 Symfony polyfill for intl's Normalizer class and related functions
symfony/polyfill-mbstring                v1.29.0 Symfony polyfill for the Mbstring extension
symfony/polyfill-php81                   v1.29.0 Symfony polyfill backporting some PHP 8.1+ features to lower PHP versions
symfony/process                          v6.0.19 Executes commands in sub-processes
symfony/property-access                  v6.0.19 Provides functions to read and write from/to an object or array using a simple string notation
symfony/property-info                    v6.0.19 Extracts information about PHP class' properties using metadata of popular sources
symfony/routing                          v6.0.19 Maps an HTTP request to a set of configuration variables
symfony/runtime                          v6.0.19 Enables decoupling PHP applications from global state
symfony/security-acl                     v3.3.3  Symfony Security Component - ACL (Access Control List)
symfony/security-bundle                  v6.0.20 Provides a tight integration of the Security component into the Symfony full-stack framework
symfony/security-core                    v6.0.19 Symfony Security Component - Core Library
symfony/security-csrf                    v6.0.19 Symfony Security Component - CSRF Library
symfony/security-http                    v6.0.20 Symfony Security Component - HTTP Integration
symfony/serializer                       v6.0.19 Handles serializing and deserializing data structures, including object graphs, into array structures o...
symfony/service-contracts                v3.0.2  Generic abstractions related to writing services
symfony/stopwatch                        v6.0.19 Provides a way to profile code
symfony/string                           v6.0.19 Provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme cluster...
symfony/translation                      v6.0.19 Provides tools to internationalize your application
symfony/translation-contracts            v2.5.0  Generic abstractions related to translation
symfony/twig-bridge                      v6.0.19 Provides integration for Twig with various Symfony components
symfony/twig-bundle                      v6.0.19 Provides a tight integration of Twig into the Symfony full-stack framework
symfony/validator                        v6.0.19 Provides tools to validate values
symfony/var-dumper                       v6.0.19 Provides mechanisms for walking through any arbitrary PHP variable
symfony/var-exporter                     v6.0.19 Allows exporting any serializable PHP data structure to plain PHP code
symfony/yaml                             v6.0.19 Loads and dumps YAML files
twig/string-extra                        v3.8.0  A Twig extension for Symfony String
twig/twig                                v3.9.3  Twig, the flexible, fast, and secure template language for PHP
PHP 8.0.30 (cli) (built: Nov 21 2023 21:41:47) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.30, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.30, Copyright (c), by Zend Technologies
VincentLanglet commented 2 months ago

Thanks.

You said it was working before, which version you were using before ? (Or did you gave the version it was still working with ?)

gekomod commented 2 months ago

For symfony 4 and symfony 5 with Sonata Admin it worked, as I expected, such miracles happen with this version

VincentLanglet commented 2 months ago

For symfony 4 and symfony 5 with Sonata Admin it worked, as I expected, such miracles happen with this version

There is tons of different version of SonataAdmin.

What is useful would be to know what was the sonata version working and the one not working. Symfony is unrelated

mvhirsch commented 2 months ago

You defined your model_class to be said admin class which can't work (as it is an admin class, and therefor not managed by doctrine).

# copied from your configuration
admin.extensions:
        class: Gekomod\ExtensionsBundle\Admin\ExtensionsAdmin
        tags:
            - name:  sonata.admin
              manager_type: orm
              model_class: Gekomod\ExtensionsBundle\Admin\ExtensionsAdmin # wrong definition, you need to fix this
              translation_domain: 'App'
              group:  # missing something here?

By entering your correct model_class which the Admin should manage, it should work fine.

Looks like you're upgrading to at least sonata-project/admin-bundle v4.8 (which I think introduces using tags)?