I'm working in a project in Symfony2 and i want to use Symfony CMF with Doctrine ORM.
In my config.yml:
knp_menu:
twig: true
cmf_routing:
dynamic:
persistence:
orm:
enabled: true
manager_name: ~
I'm getting this error:
[Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException]
You have requested a non-existent parameter "None of the managerParameters
resulted in a valid name".
Im triying to use Doctrine ORM instead of PHPCR ODM
Someone knows what can i do?
Thanks!
Related
Today i tried to copy/past an entity from a project to an other.
First i tried to create the entity with
php bin/console make:entity
And to copy/past the entity class into the file just created.
Didn't work and got this error message i can't figure out.
My configuration is a new symfony 5.4 project. And symfony 5.4 for the other project.
The only things that change is that in the first projet i used annotation system (#ORM\Table...) and the new one is attributes by default (#[ORM\...). But i used to use both on other projects and worked well.
I tried to change annotation to attribute and it works. But i would like to know how can i use both annotations and attributes on the project, it used to be the default value ?
My doctrine.yaml :
doctrine:
dbal:
url: '%env(resolve:DATABASE_URL)%'
# IMPORTANT: You MUST configure your server version,
# either here or in the DATABASE_URL env var (see .env file)
#server_version: '14'
orm:
auto_generate_proxy_classes: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
mappings:
App:
is_bundle: false
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
What i tried :
cache clear
remove/create entity
check on internet for some solutions
check if use Doctrine\ORM\Mapping as ORM; was in my file
What i tried :
cache clear
remove/create entity
check on internet for some solutions
check if use Doctrine\ORM\Mapping as ORM; was in my file
Symfony does not support both, you have to choose between of 2, so if you don't have any php version problem, both should fit
I have a question regarding YAML configuration of Doctrine in Symfony2.
I have created an entity via "doctrine:generate:entity", and chose YAML as the mapping format.
This didn't add any metadata on ../Entity/"MyEntity".php, which would allow me to update or create my schema.
As an example, if I run
./app/console doctrine:schema:create
it fails, saying:
[RuntimeException]
Bundle "MySuperBundle" does not contain any mapped entities.
My automapping is already set to "true".
If I choose to use annotation config this would not be a problem.
Did I miss something? Are there any extra steps that I should take?
Thank you in advance, regards,
Ivan
I just had a fun time looking at the Doctrine config initialisation code. What I found was:
Using auto_mapping results in various defaults being set for the single default entity manager; it leaves the type value as false
If type is false the config code looks into the default directory for likely config files, and as soon as it finds a file of a valid extension it decides that that's the way config is being done, in the order xml, yml, php
If it doesn't find any of those it assumes annotation
Do you have anything else at all in the Bundle/Resources/config/doctrine folder? If so, it might be throwing off the auto-detection.
That aside, basically if you've used defaults, and have some entity classes and valid config, what you're doing should be working without any additional config. You've said "auto_mapping" is true, but have you changed any other bit of Doctrine config?
It might be an idea to try configuring stuff explicitly, e.g. as described in the Symfony Doctrine docs, go from default config
doctrine:
dbal:
driver: "%database_driver%"
#etc
orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: true
to explicit
doctrine:
dbal:
driver: "%database_driver%"
#etc
orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: false
mappings:
MySuperBundleName:
type: yml
dir: Resources/config/doctrine
I installed stof/DoctrineExtensions in my symfony app and configured everything as it should.
When I remove an entity, the deletedAt is set and everything works, but then when I do findAll the deleted entities are still returned.
$zorgboer = $em->getRepository('stroPublicBundle:Zorgboerderij')->find(3);
$em->remove($zorgboer);
$em->flush();
$zorgboeren = $em->getRepository('stroPublicBundle:Zorgboerderij')->findAll();
#EDIT: OK I found the solution. the problem was that entity Zorgboerderij extends another entity. The softdeletable had to be on the parent. Now it works
Maybe you forgot to setup SoftDeleteableFilter in app/config.yml:
doctrine:
...
orm:
filters:
softdeleteable:
class: Gedmo\SoftDeleteable\Filter\SoftDeleteableFilter
enabled: true
This will enable the SoftDeleteable filter, so entities which were "soft-deleted" will not appear in results.
I'm using DoctrineMongoDBBundle, normally i put the documents into the MyBundle/Document directory and works fine but i want change to MyBundle/Model
after move my documents to new namespace i get a error message
[Exception]
You do not have any mapped Doctrine MongoDB ODM documents for any of your bundles...
currently i'm using annotations for set the configuration, i dont want use xml or yml. this is the current config, how i can achieve this?
# app/config/config.yml
doctrine_mongodb:
connections:
default:
server: mongodb://localhost:27017
options: {}
default_database: "%database_name%"
document_managers:
default:
auto_mapping: true
Assuming your document is Acme/Model/Invoice.
You can adjust the mapping like this:
doctrine:
odm:
# ...
mappings:
Acme:
type: annotation
is_bundle: false
dir: %kernel.root_dir%/../src/Acme/Model
prefix: Acme\Model
alias: MyDocuments
Now use the the mapping like this:
$documentManager->getRepository('MyDocuments:Invoice');
If you want to keep the document inside a bundle ...
... just use the bundle's name i.e. AcmeDemoBundle instead of Acme as the mapping-name, set is_bundle to true and the dir option will be seen as relative to the bundle's root directory.
More information on the mapping options can be found in the documentation chapter DoctrineBundle Configuration#Mapping Information.
More information on how to store documents out of bundles can be found in this blog post.
The procedure is the same for Doctrine ORM btw.
I followed this tutorial to install SonataAdmin with FOSUserBundle.
Now i keep getting this Error Message:
No entity manager defined for class Application\Sonata\UserBundle\Entity\User
But how do i set/pass the EntityManager?
I haven't found anything about configuring it or any hint on what this error means.
Any help anyone?
Edit #1:
As asked for, here is what i have in my config.yml for sonata so far:
sonata_block:
default_contexts: [cms]
blocks:
sonata.admin.block.admin_list:
contexts: [admin]
sonata.block.service.text:
sonata.block.service.rss:
Edit #2:
I added the entity manager configuration part for Doctrine2 ORM Admin thou it is mentioned in the Documentation that if left null, it should just use the default. Still, it doesn't solve my problem.
sonata_doctrine_orm_admin:
# default value is null, so doctrine uses the value defined in the configuration
entity_manager: '#doctrine.orm.entity_manager'
Edit #3:
I did set auto_mapping to true as well, even thou that also is true by default.
Still no Solution to this Problem.
When you use
php app/console sonata:admin:generate
it requests for fully qualified model class, so you'd write something like:
\Acme\DemoBundle\Entity\DemoEntity
the problem is, that when generator creates service for you it adds line:
arguments: [~, \Acme\DemoBundle\Entity\DemoEntity, AcmeDemoBundle:DemoEntityAdmin]
That breaks it.
It works with:
arguments: [~, Acme\DemoBundle\Entity\DemoEntity, AcmeDemoBundle:DemoEntityAdmin]
Notice missing "\" before Acme\Demo....
What was missing in my config.yml was:
doctrine:
[...]
orm:
[...]
entity_managers:
default:
mappings:
ApplicationSonataUserBundle: ~
SonataUserBundle: ~
Just had this problem.
Make sure you easy-extended the SonataUserBundle:
php app/console sonata:easy-extends:generate SonataUserBundle
and are loading it in AppKernel.php
new Application\Sonata\UserBundle\ApplicationSonataUserBundle(),
See documentation here:
https://github.com/sonata-project/SonataUserBundle/blob/master/Resources/doc/reference/installation.rst
Then the automapping is enough and you don't need to define manual mapping.