My problem is simply... or not....
This is my config.yml for the bundle
stof_doctrine_extensions:
default_locale: fr
translation_fallback: true
orm:
default:
translatable: true
When i use my entity translation repository with findTranslations($entity) The repository give me all the translation except the default local translation.
The problem is that i need to know if the default translation is in my bdd.
Is it a problem with stof or it's normal. And there's a way to solve my problem?
Thank you.
(And sorry for my english...)
Related
Im using FOS RestBundle and JMSSerializer (maybe its doing something i dont know) and want to returns a translated message in json. I wanted to use the translator service however the trans() method not working.
$this->get('translator')->trans('translator.key.here')
The translations seem to be loaded correctly as i dumped translator and found there the translated message under the current locale and 'translator.key.here' key. However the trans function simply gives back the key string.
Any idea?
Edit: In twig its working perfectly.
In my messages.hu yml file:
translator:
key:
here: some message
In the config also set fallbacks:
translator: { fallbacks: [hu] }
default_locale: "%locale%"
When i dumped translator in the object i found under en locale the right message key pair:
"translator.key.here" => "some message"
Try this in parameters.yml:
locale: hu
and in config.yml:
framework:
translator: { fallbacks: ["%locale%"] }
default_locale: "%locale%"
and in translation folder create file: messages.hu.yml
Well i found a solution.. still dont know why not working simply but it works if i set directly the translation domain.
translator->trans('key.goes.here', array(), 'messages); if somebody has the some issue in the future.
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 guess that this is really trivial and stupid question, but I don't know how to install Doctrine Extensions - https://github.com/beberlei/DoctrineExtensions in my Symfony2 project. I need them because of the MONTH, YEAR functions. Where should I put their folder? And should I put the whole DoctrineExtensions folder? And where to write this:
<?php
$classLoader = new \Doctrine\Common\ClassLoader('DoctrineExtensions', "/path/to/extensions");
$classLoader->register();
In a separate file? Where to put it and how to call it?
And then is this all I need to use them:
public function findOneByYearMonthDay($year, $month, $day)
{
$emConfig = $this->getEntityManager()->getConfiguration();
$emConfig->addCustomDatetimeFunction('YEAR', 'DoctrineExtensions\Query\Mysql\Year');
$emConfig->addCustomDatetimeFunction('MONTH', 'DoctrineExtensions\Query\Mysql\Month');
$emConfig->addCustomDatetimeFunction('DAY', 'DoctrineExtensions\Query\Mysql\Day');
Thank you very much in advance and sorry once again for the question, but I couldn't find a tutorial (which makes me feel even more guilty, because I guess it's too trivial when there isn't even a tutorial)
You can install it via composer. Just add it to your composer.json and then php composer.phar update beberlei/DoctrineExtensions
"beberlei/DoctrineExtensions": "*",
Then you can register functions to your ORM
doctrine:
orm:
auto_generate_proxy_classes: %kernel.debug%
entity_managers:
default:
auto_mapping: true
dql:
datetime_functions:
MONTH: DoctrineExtensions\Query\Mysql\Month
YEAR: DoctrineExtensions\Query\Mysql\Year
There also is a nice fork by wiredmedia of #beberlei which includes even more datetime_functions like DATE() itself:
This is an unsanctioned fork of https://github.com/beberlei/DoctrineExtensions since he seems to have gone off grid and is not merging pull requests.
Unfortunately Version 0.1 just includes the fork and not all the functions.
We are waiting for a stable release:
Please create taged stable version for set in my composer #2
But you can add them manually unitl a stable version is out.
Here is how to use DoctrineExtensions in the context of Symfony using the DoctrineBundle.
First install the package DoctrineExtensions:
composer require beberlei/doctrineextensions
Then add to your doctrine configuration (doctrine.yaml file) the DQL functions you want to include in your application:
doctrine:
# Register types this way in the dbal config part
dbal:
types:
carbondatetime: DoctrineExtensions\Types\CarbonDateTimeType
# Register DQL functions in the ORM part
orm:
dql:
string_functions:
FIND_IN_SET: DoctrineExtensions\Query\Mysql\FindInSet
numeric_functions:
SIN: DoctrineExtensions\Query\Mysql\Sin
datetime_functions:
DATE: DoctrineExtensions\Query\Mysql\Date
This is an example, feel free to adjust to your needs (you can remove sections).
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.
I am trying to store entities in MyBundle/OtherNamespacePart/Entity directory.
If I run doctrine:schema:create, i get this error message:
Class MyBundle/Entity/MyEntity does not exist and could not be loaded.
I don't get, why is "OtherNamespacePart" ignored (should be MyBundle/OtherNamespacePart/Entity/MyEntity). I checked whole project if there is everything namespaced and named correctly and it seems to me ok. If i store entities directly in entity directory, it works (just need to remove all "OtherNamespacePart").
Isn't problem in console command tool, that expects entities in entity directory? Is there any workaround or configuration option?
You can do this by providing custom mappings in your config.yml
e.g.:
doctrine:
orm:
auto_generate_proxy_classes: %kernel.debug%
auto_mapping: false
mappings:
name:
type: xml
dir: %kernel.root_dir%/../src/Your/Bundle/Resources/config/doctrine
alias: MyModels
prefix: MyBundle\OtherNamespacePart\Entity
is_bundle: false