Translate Validation Constraint Messages on Symfony - symfony

In order to have error messages in different languages, I am following the instructions under this link:
https://symfony.com/doc/current/validation/translations.html
I made the validator files with yaml:
For instance:
# translations/validators.en.yml
author.name.not_blank: Please enter the name of the author.
Notice: I tried the extensions yaml and yml
And in src/entity/Data.php
/**
* #var string
*#Assert\NotBlank(message="author.name.not_blank")
*/
private $author;
I just get the message "author.name.not_blank" instead of "Please enter the name of the author."
I cleared the cache like this:
https://symfony.com/doc/2.7/console/usage.html
php app/console cache:clear --env=prod
I get the temporary message on the terminal "Clearing the cache for the prod environment with debug false"
So my questions are: Am I doing something wrong in clearing the cache?
I am using Symfony 2.7
Is there something I am missing ?
By the way, all other translations from files such as
translations/messages.en.yml
are functionning perfectly well.
Thank you very much!

I see your code is fine:
now you can check additional stuff:
app/config:
translator: { fallbacks: ["%locale%"] }
and be sure which environment are you in.
instead of
php app/console cache:clear --env=prod
try
php app/console cache:clear
hope this will helps.

Related

Symfony & Doctrine - Repository or Doctrine cache to clear?

My environment :
Symfony 2.7
Custom Bundle "IpadBundle".
Entity is "Checksum.php" and my controller is "MainController.php".
All work perfect when i Use the findAll() method on my repo. Then
I added 2 new properties in my entity ($file_path and $creation_date)
Getters and Setters were generated by app/console doctrine:generate:entities IpadBundle:Checksum
Mysql database has been updated via doctrine:schema:update --force
I went to my phpmyadmin to fill manually the 2 new cols
... but result of findAll() doesn't include these new cols ! I tried :
cache:clear --env=prod
cache:warmup
"$cacheDriver = new \Doctrine\Common\Cache\ArrayCache();" + "$cacheDriver->deleteAll();"
"app/console doctrine:cache:clear-metadata" + "app/console doctrine:cache:clear-query" + "app/console doctrine:cache:clear-result".
But no results.
Any idea ?
Sometimes that happend to me and the only thing I do is restart apache and whola. Is weird IDK why apache saves some cache for entities, try it and let me know if that works for you. Good Luck !

Symfony debug still enabled after cache:warmup --no-debug

I have Symfony 3.2.7 installed on a production server.
I issue the following commands:
bin/console cache:clear --no-warmup --no-debug --env=preview
bin/console cache:warmup --no-debug --env=preview
bin/console --version
I get the following output, showing that debug is enabled.
Symfony 3.2.7 (kernel: app, env: preview, debug: true)
What am I missing?
Nevermind.
Bad programmer on device.
The monolog.handlers.main.level value was set to debug.
Duh.
Sorry for the noise.
I've never used bin/console in a production server, but I don't think that information is reliable for your use case.
If you open the bin/console script in an editor you will see:
$debug = getenv('SYMFONY_DEBUG') !== '0' && !$input->hasParameterOption(['--no-debug', '']) && $env !== 'prod';
As you can see the $debug parameter is determined by a combination of environment variables and parameters.
Every time you call this script this value is recalculated.

Symfony2 updated entity works on dev but not on prod

I recently had to add new 'field' to Product in my sonata application so i added it in entity devinition ...
/**
* #var integer $deliveryTime
*/
protected $deliveryTime;
/**
* Get deliveryTime
*
* #return integer $deliveryTime
*/
public function getDeliveryTime()
{
return $this->deliveryTime;
}
/**
* #param int $deliveryTime
*/
public function setDeliveryTime($deliveryTime)
{
$this->deliveryTime = $deliveryTime;
}
in ORM
<field name="deliveryTime" column="delivery_time" type="integer" nullable="true" />
in ProductProvider
$formMapper->add('deliveryTime', 'integer')
and in all the views
It works perfectly on my local environment but when i moved it to production it doesn't work.
Funny thing is that if i access dev environment on my production server it shows the delivery time for products but on prod environment it doesn't.
I cleared cache with --env=prod option, even physically deleted cache files from both dev and prod folders but it won't help.
Database is not the issue because it wouldn't work on dev env if the reason was database.
Any ideas what else should i do to make it work on prod env?
(i can switch to dev env without the toolbar but it's not 'nice' approach:)
UPDATE: #moonwave99 yes i did update the database and there's nothing related in app_prod.log
what doesn't work on prod and works on dev:
- showing delivery time for product from the database in product view
- showing/updating delivery time through the admin panel
This was strange - i restarted apache service on production server and now it works.
Try running a few commands,
php app/console doctrine:schema:update --force
php app/console cache:clear
php app/console cache:clear --env=prod --no-debug
if that fails re-push your code
and re run above
Hope that helps
You should to reload APC. Prod environment saves doctrine cache in this system.
If you use PHP + Apache - restart apache
If you use PHP-FPM - restart php-fpm.

Symfony2 - Removed FOS User Bundle manually and now cannot clear cache in production mode

I installed FOS Userbundle to learn from it, but decided I didn't need it anymore. I then did the following to remove it. After removing, I ran composer update.
removed the bundle from the vendor folder
removed from the appKernel
removed from the composer.json file
removed the entity User.php file
removed the settings from config.yml, security.yml, routing.yml
Now when I attempt to clear cache for production mode I get the following error below. Clearing cache in dev mode works fine.
Can show me what I am doing wrong or what I am missing to remove FOS User Bundle and be able to clear cache in production mode?
PHP Fatal error: Class 'FOS\UserBundle\EventListener\LastLoginListener' not found in /var/www/html/HealthFitness/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/ContainerAwareEventDispatcher.php on line 142
PHP Stack trace:
PHP 1. {main}() /var/www/html/HealthFitness/app/console:0
PHP 2. Symfony\Component\Console\Application->run() /var/www/html/HealthFitness/app/console:27
PHP 3. Symfony\Bundle\FrameworkBundle\Console\Application->doRun() /var/www/html/HealthFitness/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:121
PHP 4. Symfony\Component\DependencyInjection\Container->get() /var/www/html/HealthFitness/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:86
PHP 5. appProdProjectContainer->getEventDispatcherService() /var/www/html/HealthFitness/app/bootstrap.php.cache:2037
PHP 6. Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher->addSubscriberService() /var/www/html/HealthFitness/app/cache/prod/appProdProjectContainer.php:343
Your error indeed probably come from a cache error.
Have you this error executing php app/console cache:clear --env=prod ?
You can else delete app/cache/prod/* manually.
In case you can't remove the files manually this should work as well.
You could also use a --no-warmup and --no-optional-warmers switches:
cache:clear --no-warmup --no-optional-warmers --env=prod
that way it should not try to recreate the cache of non existing classes and then do a
cache:warmup --env=prod
Manually removing cache is faster though, but you still warm it up.

Update schema just from yml in Symfony2 with Doctrine

I want to add an item like this just to the src/Acme/AdminBundle/Entity/Artist.orm.yml:
email:
type: string
column: email_address
length: 150
but I'm forced to do the same in the file Acme/AdminBundle/Entity/Artist
/**
* #var string $email
*/
private $email;
If I don't do it, when I update the schema it shows an error:
php app/console doctrine:schema:update --force
[Doctrine\ORM\Mapping\MappingException]
An error occurred in Acme\AdminBundle\Entity\Artist
[ReflectionException]
Property email does not exist
I generated the Bundle with the yml option at the beginning.
First, generate the entity class file
php app/console doctrine:generate:entities [Your]/[Bundle]/Entity/Artist --path="src/" --no-backup
The "--path" param must be given if there is a new entity to be generated.
Then, update your schema:
php app/console doctrine:schema:update --force
I had the same problem and I managed to solve it.
doctrine:generate:entity generates the .php entity file at "Entity" but it also generates a orm file at "Resources/config/doctrine" which can create conflicts if you modify the .php entity file.
I just deleted the orm files and it works as expected.

Resources