Having an issue with the final stage of the setup of Easy Admin in a fresh Symfony 3 install,
at the "Your First Backend" : Creating the backend for those entities just require you to add the following configuration in the app/config/config.yml file:
# app/config/config.yml
easy_admin:
entities:
- AppBundle\Entity\Product
- AppBundle\Entity\Category
- AppBundle\Entity\User
When I do this I get error :
[ReflectionException] Class
AppBundle\Entity\Product does not exist
All the previous commands for setup installed without error, including installing the assets.
In documentation of EasyAdminBundle You have
Let's suppose that your Symfony application defines three Doctrine ORM entities called Product, Category and User.
In entities section you need to list already existing in your app Entities. If you don't have any - create it.
Docs: https://github.com/javiereguiluz/EasyAdminBundle/blob/master/Resources/doc/getting-started/2-first-backend.md
Related
After creating an Entity and Repository from an existing pre-doctrine database, I am unable to make an initial migration. It gave me this error [ERROR] The version "latest" couldn't be reached, there are no registered migrations. Any idea how to do an initial migration without starting fresh? And for some reason, the migration folder exists outside the src folder, why is it so? In a previous project, the migration folder exists inside the src folder.
Any insight would be appreciated. Thank you for reading.
EDIT: doctrine_migrations.yaml:
doctrine_migrations:
migrations_paths:
# namespace is arbitrary but should be different from App\Migrations
# as migrations classes should NOT be autoloaded
'DoctrineMigrations': '%kernel.project_dir%/migrations'
The commands I used to generate the Entity and its Repository is as follows:
php bin/console doctrine:mapping:import "App\Entity" annotation --path=src/Entity
modified the #ORM\Entity => #ORM\Entity(repositoryClass="App\Repository\UserRepository") in the entity .php
php bin/console make:entity --regenerate
Then when I run bin/console doctrine:migrations:migrate, the error pops up.
Work for me
doctrine_migrations:
migrations_paths:
'App\Migrations': '%kernel.project_dir%/src/Migrations'
and use for migration classes
namespace App\Migrations;
THis is my migrations config.You can test it :
doctrine_migrations:
dir_name: '%kernel.project_dir%/src/Migrations'
# namespace is arbitrary but should be different from App\Migrations
# as migrations classes should NOT be autoloaded
namespace: DoctrineMigrations
For migration commande i use : php bin/console d:m:diff and after this you can use the migration number with this commande :
php bin/console d:m:e --up the_migration_number
I tried most of the methods but it seems that it is possible to generate the migration. However, changes to the entity will not be detected by doctrine.
For example, if I change the field of name to username, php bin/console doctrine:migration:diff does not detect the changes.
What I found worked was exporting the database as .sql, creating the entity the normal way, and manually typing in the fields. Delete the generated table in phpmyadmin, and importing the data back in. Only then would it be working as I want it to be.
I'm starting to use Sonata with Symfony 4.
I try to generate an admin with the command line "make:sonata:admin" and i've an error at the end of the process like this:
2018-10-11T15:55:23+00:00 [error] Error thrown while running command "make:sonata:admin". Message: "There are no model managers registered."
In AdminMaker.php line 286:
There are no model managers registered.
So I try wit hthe other command line "sonata:admin:generate" and I have an other error like this :
Welcome to the AdminBundle object ACL generator
This command helps you to generate ACL entities for the objects handled by the AdminBundle.
If the step option is used, you will be asked if you want to generate the object ACL entities for each Admin.
You must use the shortcut notation like AcmeDemoBundle:User if you want to set an object owner.
Admin class is using a manager type that has no manipulator implemented : ignoring
Admin class is using a manager type that has no manipulator implemented : ignoring
Admin class is using a manager type that has no manipulator implemented : ignoring
My implementation code is like this :
src
Entity
Clients
Vehicules
Can you help me please ?
Thanks a lot for your answer
Try to config the service, so you can give the model manager that you use.
services:
sonata.admin.maker:
class: Sonata\AdminBundle\Maker\AdminMaker
arguments: ['%kernel.project_dir%', ['#sonata.admin.manager.orm']]
tags:
- { name: maker.command }
You need to install Doctrine ORM Admin Bundle first
composer require sonata-project/doctrine-orm-admin-bundle
I am building a company Symfony2 library that includes several bundles and a library of classes that can be used by any code. The plan is to eventually turn this into an internal package and install it into projects via composer so that it will live in the vendor directory.
One component of the library has a pair of database entity classes and a single repository class associated with it.
Because the only logic associated with these classes is contained in the repository class, it doesn't seem to make sense to to surround it with a bundle.
I have, as yet, been unable to get Doctrine to load this repository. It initially failed with a
The class 'Dplh\Library\DplhEnum\Entity\EnumGroupRepository' was not found in the chain configured namespaces Dplh\DplhSecurityBundle\Entity
exception. (The reference to my security bundle was initially rather confusing. Turns out that this is Doctrine helping out by listing all of the known entity namespaces (see Symfony error The class XXX was not found in the chain configured namespaces XXX)).
As I understand it, this happens because Doctrine is configured to use auto-mapping and expects all entities to be defined in src/WhateverBundle/Entity directories.
This can be changed with additional Doctrine configuration for specific mappings in config.yml (http://zalas.eu/how-to-store-doctrine-entities-outside-of-a-symfony-bundle/).
So far, I have been unable to get this to work either. I expect it's a minor config thing somewhere. I added the following to config.yml:
doctrine:
dbal:
# ...
orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: true
mappings:
DplhEnum:
type: annotation
is_bundle: false
dir: %kernel.root_dir%/../src/Dplh/Library/DplhEnum/Entity
prefix: Dplh\Library\DplhEnum\Entity
alias: DplhEnum
I get two different exceptions depending on my call to getRepository().
// Using the fully-qualified class name.
$this->getEntityManager()->getRepository('Dplh\Library\DplhEnum\Entity\EnumGroup' )
This throws
Attempted to load class "EnumGroupRepository" from namespace "Dplh\DplhEnumBundle\Entity".
Did you forget a "use" statement for another namespace?
// Using the alias.
$this->getEntityManager()->getRepository('DplhEnum\EnumGroup' )
this throws
Class 'DplhEnum\EnumGroup' does not exist
I have verified that the EnumGroupRepository.php file is in the src/Dplh/Library/DplhEnum/Entity directory and the EnumGroupRepository class is in the Dplh\Library\DplhEnum\Entity namespace and that they are in the correct directory.
I'm using Symfony2 with Doctrine to try and update a table schema. I was able to create the table. I was also able to populate the table. However after updating the comments in the Entity (I wanted some fields to become nullable), those changes did NOT get picked up.
I did create the entity with the "Annotations" option chosen. But when I added this line "nullable=true" to the Entity on the field imageName nothing happens. ie: when I run "./app/console doctrine:schema:update" I get the following output "Nothing to update - your database is already in sync with the current entity metadata."
Note, I have tried deleted the table via: ./app/console doctrine:database:drop --force and then recreating it via: ./app/console doctrine:database:create and then also ./app/console doctrine:schema:create but it STILL does not add my updated nullable field to imageName.
I was able to figure this out. I first of all created my entity "Foobar" using yml as the Configuration format. I then wanted to use "annotation" as the configuration format so I manually deleted the Entity folder (I only had one table created), however I did NOT delete the configuration yml in the Resources/config/doctrine/Foobar.orm.yml.
Thus when I created the entity again, this time using the annotation as the configuration format, it was still linking to the yml configuration. Removing that solved all the troubles.
I have however decided to stick to yml as I feel it is a little easier to read than the Doctrine Metadata found in the comments.
I had been stuck with this for almost 2 days. Removing all the file in /src/AppBundle/Resources/config/doctrine resolve my issue.
For me, the key was to clear Redis cache.
php app/console redis:flushdb
I has this problem too. Have you right annotation before class declaration?
/**
*
* #ORM\Entity <- this does the trick
*/
class MyEntityName
{
...
Check doctrine.yaml config file for orm mappings:
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
As you see here all entities should have prefix (namespace) App\Entity
You have to check your entities namespace, it should be App\Entity or whatever you want in config
I have integrated sonata admin bundle. I then integrate sonata news bundle successfully . Then I created a custom bundle. I want to configure this bundle as my CMS bundle using sonata bundle. I am able to display my CMS bundle in admin section but when I try to to edit or add new item I am getting an error:
No entity manager defined for class Fcse\CmsBundle\Entity\Book 500
Internal Server Error - RuntimeException
Book is my entity when i run command
app/console doctrine:schema:update --force
Book table is also not creating. Am I missing something in configuration?
my config file is large. i am posting the code of my cms bundle.
fcse_cms:
title: Sonata Project
link: http://local.demo
description: Cool bundles on top of Symfony2
salt: 'secureToken'
class:
book: Fcse\CmsBundle\Entity\Book
admin:
book:
class: Fcse\CmsBundle\Admin\BookAdmin
controller: SonataAdminBundle:CRUD
translation: CmsBundle
doctrine:
orm:
entity_managers:
default:
#metadata_cache_driver: apc
#query_cache_driver: apc
#result_cache_driver: apc
mappings:
FcseCmsBundle: ~
and i import this file in app/config.yml.