Symfony + sonata + translation : You have requested a non-existent parameter "locale" - symfony

New to symfony i installed Sonata composer require sonata-project/admin-bundle and translator service composer require symfony/translation
As desciribed on symfony manual (manual)
I added
# config/packages/framework.yaml
framework:
translator: { fallbacks: ['%locale%'] }
but when I make a php bin/console cache:clear i get the error
*In ParameterBag.php line 100:
You have requested a non-existent parameter "locale".*
Thank you for your help,

to solve add in services.yaml:
parameters:
locale: 'en' (en -> english, it -> italian ecc..)
and in framework.yaml
framework:
default_locale: '%locale%'
translator:
fallbacks:
- '%locale%'

Related

Unrecognized field gallery in Symfony prod mode

I'm developing web site with Symfony 4.4, using SonataAdmin (^3.56), Doctrine ORM Admin (^3.12), Sonata Media (^3.22) and SonataClassification (^3.9) bundles. My web site works perfectly in dev mode. Problem is when I change it to prod mode.
.env
APP_ENV=prod
APP_DEBUG=0
When I access routes with SonataMedia gallery then I get error 500. Log file (prod.log) contains the following content:
request.CRITICAL: Uncaught PHP Exception Doctrine\ORM\ORMException: "Unrecognized field: gallery" at /home/repincln/dev/site/vendor/doctrine/orm/lib/Doctrine/ORM/ORMException.php line 101 {"exception":"[object] (Doctrine\\ORM\\ORMException(code: 0): Unrecognized field: gallery at /home/repincln/dev/site/vendor/doctrine/orm/lib/Doctrine/ORM/ORMException.php:101)"} []
In Controller I have:
...
$medias = $this->getDoctrine()->getRepository("ApplicationSonataMediaBundle:GalleryHasMedia")->findBy(array('gallery' => $article->getGallery()));
...
If i dump $medias in dev mode, it looks OK, with all images in gallery, but in production mode it doesn't work.
A similar thing happens in SonataAdmin Admin->Classification
request.CRITICAL: Uncaught PHP Exception Doctrine\ORM\Query\QueryException: "[Semantical Error] line 0, col 84 near 'parent IS NU': Error: Class App\Application\Sonata\ClassificationBundle\Entity\Category has no field or association named parent" at /home/repincln/dev/site/vendor/doctrine/orm/lib/Doctrine/ORM/Query/QueryException.php line 65 {"exception":"[object] (Doctrine\\ORM\\Query\\QueryException(code: 0): [Semantical Error] line 0, col 84 near 'parent IS NU': Error: Class App\\Application\\Sonata\\ClassificationBundle\\Entity\\Category has no field or association named parent at /home/repincln/dev/site/vendor/doctrine/orm/lib/Doctrine/ORM/Query/QueryException.php:65, Doctrine\\ORM\\Query\\QueryException(code: 0): SELECT c FROM App\\Application\\Sonata\\ClassificationBundle\\Entity\\Category c WHERE c.parent IS NULL at /home/repincln/dev/site/vendor/doctrine/orm/lib/Doctrine/ORM/Query/QueryException.php:43)"} []
and Tags, Collections, Media. Only Contexts is working normal. Gallery for example looks like:
config/packages/prod/doctrine.yaml
doctrine:
orm:
auto_generate_proxy_classes: false
metadata_cache_driver:
type: service
id: doctrine.system_cache_provider
query_cache_driver:
type: service
id: doctrine.system_cache_provider
result_cache_driver:
type: service
id: doctrine.result_cache_provider
services:
doctrine.result_cache_provider:
class: Symfony\Component\Cache\DoctrineProvider
public: false
arguments:
- '#doctrine.result_cache_pool'
doctrine.system_cache_provider:
class: Symfony\Component\Cache\DoctrineProvider
public: false
arguments:
- '#doctrine.system_cache_pool'
framework:
cache:
pools:
doctrine.result_cache_pool:
adapter: cache.app
doctrine.system_cache_pool:
adapter: cache.system
config/packages/doctrine.yaml
doctrine:
dbal:
url: '%env(resolve:DATABASE_URL)%'
types:
json: Sonata\Doctrine\Types\JsonType
orm:
auto_generate_proxy_classes: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
Article.php
...
/**
* #ORM\ManyToOne(targetEntity="App\Application\Sonata\MediaBundle\Entity\Gallery");
*/
private $gallery;
...
As i wrote in development mode everything is working fine.
The problem persists even though I did (many times):
APP_ENV=prod APP_DEBUG=0 php bin/console cache:clear
php bin/console cache:clear
remove var/cache and var/log directories, and create them again
php bin/console doctrine:cache:clear-metadata
restart apache
change permissions (777) to uploads folder
configure apcu
-How to configure apcu for doctrine in Symfony5
use Symfony cache pool -
https://github.com/symfony/symfony/issues/24545#issuecomment-336419270
try this -
Doctrine 2.5: Unrecognized field (but only in Symfony's prod mode)
Any ideas what else can I do? I think there is a problem with cache ... somewhere.
I finally found a solution.
I had in the config/bundles.php
Sonata\EasyExtendsBundle\SonataEasyExtendsBundle::class => ['dev' => true, 'test' => true],
It must be:
Sonata\EasyExtendsBundle\SonataEasyExtendsBundle::class => ['all' => true],

How to choose locale for STOF translatable with NelmioAliceBundle Fixture in Symfony

Hy,
For some time know I have an issue with my test scenario.
I use behat/mink ~2.0 and Nelmio/Alice ^2.x in my Symfony project.
On some of my project I use the doctrine extension translatable to manage i18n on my buisness entity.
When alice persist my fixture he seems to ignore my default_locale parameter and will always create them with en as locale value.
In order to test my locale switcher I need a way to choose my locale for the project in test environnement or/and persist fixture with different locale.
My fixture are wright as follow
AcmmeBundle\CoreBundle\Entity\Universe:
universe1:
title: <word()>
templates: [#template1]
collections: [#collection1, #collection2]
categories: [#category1, #category2]
Load in my test like this
#alice(User)
#alice(Category)
#alice(Collection)
#alice(Universe)
#alice(Page)
#alice(HomePage)
#reset-schema
#javascript
Feature: I test api GET /api/someEntity
And my behat.yml.dist
default:
autoload:
'': features/bootstrap
suites:
default:
contexts:
- Victoire\Tests\Features\Context\FeatureContext
- Victoire\Tests\Features\Context\JavascriptContext
- Victoire\Tests\Features\Context\VictoireContext
- Knp\FriendlyContexts\Context\MinkContext
- Knp\FriendlyContexts\Context\AliceContext
- Knp\FriendlyContexts\Context\EntityContext
- Knp\FriendlyContexts\Context\TableContext
- FeatureContext
- PageContext
- ApiContext
formatters:
html:
output_path: %paths.base%/web/build/html/behat
pretty:
output_path:
extensions:
emuse\BehatHTMLFormatter\BehatHTMLFormatterExtension:
name: html
renderer: Twig,Behat2
file_name: Index
print_args: true
print_outp: true
loop_break: true
jarnaiz\JUnitFormatter\JUnitFormatterExtension:
filename: report.xml
outputDir: %paths.base%/test-reports/
Behat\Symfony2Extension:
kernel:
path: app/AppKernel.php
debug: true
Behat\MinkExtension\ServiceContainer\MinkExtension:
base_url: 'http://127.0.0.1/app_test.php'
selenium2:
wd_host: 127.0.0.1:4444/wd/hub
capabilities: { "browser": "firefox"}
goutte: ~
symfony2: ~
default_session: symfony2
browser_name: firefox
Knp\FriendlyContexts\Extension:
entities:
namespaces:
- Acme
- Victoire
smartTag: smartStep
alice:
locale: fr_FR
fixtures:
Media: features/fixtures/media.yml
Template: features/fixtures/template.yml
User: features/fixtures/user.yml
Survey: features/fixtures/survey.yml
Tag: features/fixtures/tag.yml
Collection: features/fixtures/collection.yml
Category: features/fixtures/category.yml
Universe: features/fixtures/universe.yml
Page: features/fixtures/Victoire/page.yml
HomePage: features/fixtures/Victoire/Pages/home.yml
dependencies:
Template: [Media]
User: [Template]
Survey: [Tag]
HomePage: [Page]
According to http://docs.behat.org/en/v2.5/guides/7.config.html use
export BEHAT_PARAMS="formatter[name]=progress&context[parameters][base_url]=http://localhost"
and override "_locale" parameter in route
Well actually the answer was realy simple.
Just by using fixture for Translation class
universeTranslation1:
title: <word()>
locale: fr
translatable: #universe1
universeTranslation2:
title: <word()>
locale: en
translatable: #universe1
universeTranslation3:
title: <word()>
locale: fr
translatable: #universe2
universeTranslation4:
title: <word()>
locale: en
translatable: #universe2

Symfony2 Sylius setting the default locale

When I want to create a Shipment I get the error:
An exception has been thrown during the rendering of a template ("No locale has been set and current locale is undefined.") in SonataAdminBundle::standard_layout.html.twig at line 148.
I think I need to set the default locale for sylius, but I tried alot of examples, none of them helped..
I currently have this setup:
Config.yml:
sylius_shipping:
driver: doctrine/orm # Configure the Doctrine ORM driver used in documentation.
classes:
shipping_method:
model: Application\Sylius\ShippingBundle\Entity\ShippingMethod
translation:
model: Application\Sylius\ShippingBundle\Entity\ShippingMethodTranslation
shipping_method_rule:
model: Application\Sylius\ShippingBundle\Entity\Rule
shipment:
model: Application\Sylius\ShippingBundle\Entity\Shipment
shipment_item:
model: Application\Sylius\ShippingBundle\Entity\ShipmentItem
shipping_category:
model: Application\Sylius\ShippingBundle\Entity\ShippingCategory
#stof_doctrine_extensions:
# orm:
# default:
# timestampable: true
parameters:
sylius.locale: %locale%
#sylius_locale:
# driver: doctrine/orm
sylius_translation:
default_locale: "%locale%"
#sylius_translation:
# default_locale: %sylius.locale%
Parameters.yml:
sylius.currency_importer.ecb.base_currency: EUR
sylius.currency_importer.open_exchange_rates: EDITME
sylius.locale: en_US
Nothing works..
UPDATE
By changing my config to this:
framework:
#esi: ~
translator: { fallback: %sylius.locale% }
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
templating:
engines: ['twig']
#assets_version: SomeVersionScheme
default_locale: "%sylius.locale%"
parameters:
sylius.locale: 'en'
#sylius_locale:
# driver: doctrine/orm
sylius_translation:
default_locale: %sylius.locale%
I still get the same error. I cleared my cache.
Try %sylius.locale%. It looks like you've just not put in the full name of the parameter in your config file.
If you've updated the value and it's not working, make sure you clear your cache.
$ app/console cache/clear --env=dev
$ app/console cache/clear --env=prod
You will also require something like this:
imports:
- { resource: parameters.yml }
Otherwise the parameters you enter will not be loaded into the configuration file.

symfony2: add parameters.yml.dist in config.yml

Im trying to add parameters.yml.dist inside config.yml this way:
- { resource: parameters.yml }
- { resource: parameters.yml.dist }
twig:
debug: %kernel.debug%
strict_variables: %kernel.debug%
globals:
base_url_algoritmo: %base_url_algoritmo% <<<<<<< this parameter is inside paramters.yml.dist
but I get
[Symfony\Component\Config\Exception\FileLoaderLoadException]
Cannot load resource "parameters.yml.dist".
".dist" is used only for distribution (dummy data that will be used on composer install/update) - so this idea of including it in config.yml is not so good ;)

Symfony2 - No route found for "GET /Categoria/"

Symfony2 returns No route found for "GET /Categoria/" when I try to access to localhost/Symfony/web/app_dev.php/Categoria/, the page localhost/Symfony/web/app_dev.php/hello/Guido works.
src\grupo85\entregaFinalBundle\Resources\config\routing.yml:
grupo85entrega_final_homepage:
pattern: /hello/{name}
defaults: { _controller: grupo85entregaFinalBundle:Default:index }
app\config\routing.yml:
grupo85entrega_final:
resource: "#grupo85entregaFinalBundle/Resources/config/routing.yml"
prefix: /
grupo85entregaFinalBundle:
resource: "#grupo85entregaFinalBundle/Controller/"
type: annotation
prefix: /
php app/console route:debug
categoria GET ANY ANY /categoria/
categoria_create POST ANY ANY /categoria/
categoria_new GET ANY ANY /categoria/new
categoria_show GET ANY ANY /categoria/{id}
categoria_edit GET ANY ANY /categoria/{id}/edit
categoria_update PUT ANY ANY /categoria/{id}
categoria_delete DELETE ANY ANY /categoria/{id}
I've also tried to run the cache:clear --env prod command and remove pp/cache folder manually.
What's wrong?
Thanks.
Please understand error message. You have not route for /Categoria/. You have route for /categoria/. Please notice lower case. SF2 router recognizes lower and upper cases.

Resources