When I enable the 'dev' mode in my Symfony 4 app (that is already online in a shared hosting service) it shows this message:
(1/1) ParameterNotFoundException
You have requested a non-existent parameter "locale".
in ParameterBag.php (line 100)
at ParameterBag->get('locale')
in EnvPlaceholderParameterBag.php (line 57)
at EnvPlaceholderParameterBag->get('locale')
in ParameterBag.php (line 216)
at ParameterBag->resolveString('%locale%', array('locale' => true))
in ParameterBag.php (line 187)
...
and does not allow to debug the app. My config/services.yml code is as default:
# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: 'en'
services:
# default configuration for Services in *this* file
_defaults:
autowire: true # Automatically injects dependencies in your Services.
autoconfigure: true # Automatically registers your Services as commands, event subscribers, etc.
public: false # Allows optimizing the container by removing unused Services; this also means
# fetching Services directly from the container via $container->get() won't work.
# The best practice is to be explicit about your dependencies anyway.
...
Please, someone can help me to fix this error.
Had the same problem during the fresh symfony 4.3 + sonata admin bundle installation.
As a solution I added locale parameter:
// /config/services.yaml
parameters:
locale: 'en'
While I am not a Symphony expert the documentation appears to allow anything in the parameters section, but it does mention also defining the values in the .env.dist file as well for them to be used here.
http://symfony.com/doc/current/best_practices/configuration.html#canonical-parameters
When upgrading from symfony 4.2 to symfony 4.4 I also got this error when composer commands.
This parameter seems so be used in config/packages/translation.yml.
Updating the symfony/translation recipe which no longer refers to %locale% but hardcode 'en' solves the problem for me.
Simply run composer recipes:install symfony/translation --force -v
Related
I have a registered service where I inject the content of a json as argument (see followed configuration, App\Service\Authenticator service)
parameters:
env(LDAP_CONFIG_FILE): '../auth.json'
services:
_defaults:
autowire: true
autoconfigure: true
App\:
resource: '../src/'
exclude:
- '../src/DependencyInjection/'
- '../src/Entity/'
- '../src/Kernel.php'
App\Service\Authenticator:
arguments:
$config: '%env(json:file:resolve:LDAP_CONFIG_FILE)%'
$environment: '%env(APP_ENV)%'
When I try to inject this service in a controller, this works fine as expected. But when I inject the service into a command I get this error :
> php bin/console app:execute
[WARNING] Some commands could not be registered:
In EnvVarProcessor.php line 136:
File "../auth.json" not found (resolved from "resolve:LDAP_CONFIG_FILE").
Command "app:execute" is not defined.
And if I replace env(LDAP_CONFIG_FILE) by auth.json it work in a command but not in a controller anymore.
How can I configure to make it work in both commands and controllers ?
Edit: I found a temporary fix with the default processor but I really want a clean solution.
Following the advice from this thread, I ran the following in my existing Symfony 3.4 application's home directory:
composer require api-platform/core v2.2
... after which composer spit out a bunch of green messages confirming successful installation.
However, when I visit http://localhost:8443/ as suggested here, I get 'can't establish a connection'.
My Symfony app is still running normally when I go to http://localhost. Are there additional steps required to get the API Platform documentation running?
(For Symfony2/3)
Use this package with composer:
composer require api-platform/core
Configure the bundle manually in AppKernel.php:
$bundles = [
// [...]
new ApiPlatform\Core\Bridge\Symfony\Bundle\ApiPlatformBundle(),
];
Add this in your app/config/routing.yml
api:
resource: '.'
type: 'api_platform'
prefix: '/api' # Optional
If needed, add your specific configuration in app/config/config.yml
api_platform:
title: 'specific name'
(complete configuration https://api-platform.com/docs/core/configuration/)
I hope it will help.
I'm upgrading a existing Symfony 3.3 application to Symfony 3.4.
I'm getting a console command auto-registration warning in spite of the fact that I've defined the command in the bundle's services.yml file. The warning:
[2017-12-14 12:22:19] php.INFO: User Deprecated: Auto-registration of
the command "Dplh\DplhIssuesBundle\Command\IssuesReportCommand" is
deprecated since Symfony 3.4 and won't be supported in 4.0. Use PSR-4
based service discovery instead.
The entry in Dplh/DplhIssuesBundle/Resources/config/services.yml:
services:
Dplh\DplhIssuesBundle\Command\IssuesReportCommand:
public: true
tags: ['console.command']
calls:
- [ saveDependencies, [ '#logger' ]]
I am positive that the services.yml file is being processed by Symfony because if I intentionally create a syntax error in it, Symfony reports that the file contains invalid YAML.
Finally found it.
There was a reference to the Dplh\DplhIssuesBundle\Command\IssuesReportCommand class in another bundle's services.yml file (copy/paste error, I'm sure).
Removing that reference removed the error.
I am nearly finished with installing most of the Sonata bundles in Symfony CMF. For now. my final step is finishing with the Sonata PageBundle. I installed all needed dependencies and needed bundles, I changed several config or routing files from app/config using this manual (http://sonata-project.org/bundles/page/master/doc/reference/installation.html).
The problem appears when I want to to do the 'last' step;
php app/console sonata:easy-extends:generate SonataPageBundle
I receive this error:
{ParameterNotFoundException: The service "sonata.page.admin.block" has a dependency on a non-existent parameter "sonata.block.container.types". Did you mean this: "sonata.page.block.container.class"?}
Okay, it is obvious that a dependency parameter is missing, but I am unable to pinpoint the exact problem.
My sonata_page & sonata_block from app/config/config.php;
sonata_page:
multisite: host
use_streamed_response: true # set the value to false in debug mode or if the reverse proxy does not handle streamed response
ignore_route_patterns:
- ^(.*)admin(.*) # ignore admin route, ie route containing 'admin'
- ^_(.*) # ignore symfony routes
ignore_routes:
- sonata_page_cache_esi
- sonata_page_cache_ssi
- sonata_page_js_sync_cache
- sonata_page_js_async_cache
- sonata_cache_esi
- sonata_cache_ssi
- sonata_cache_js_async
- sonata_cache_js_sync
- sonata_cache_apc
ignore_uri_patterns:
- ^/admin\/ # ignore admin route, ie route containing 'admin'
page_defaults:
homepage: {decorate: false} # disable decoration for homepage, key - is a page route
default_template: default # template key from templates section, used as default for pages
templates:
default: { path: 'SonataPageBundle::layout.html.twig', name: 'default' }
2columns: { path: 'SonataPageBundle::2columns_layout.html.twig', name: '2 columns layout' }
# manage the http errors
catch_exceptions:
not_found: [404] # render 404 page with "not_found" key (name generated: _page_internal_error_{key})
fatal: [500] # so you can use the same page for different http errors or specify specific page for each error
sonata_block:
# context_manager: sonata.page.block.context_manager
default_contexts: [cms]
blocks:
sonata.admin.block.admin_list:
contexts: [admin]
#sonata.admin_doctrine_orm.block.audit:
# contexts: [admin]
sonata.block.service.text:
sonata.block.service.rss:
sonata.page.block.container:
sonata.page.block.children_pages:
There is a similar question here on SO, but unanswered for 4 months, Google doesn't have any info (that I was able to find) on this issue.
If someone can point out what is going wrong and where, I would love to hear it..
There is no support for SonataPageBundle by the CMF project yet. So I guess the "symfony-cmf" tag is incorrect?
I implementing Mmoreram gearman bundle in my symfony(2.4) project.
I have website that users make action and triggers jobs.
like:
# Get Gearman and tell it to run in the background a 'job'
$id = $this->params['gearman']->doHighBackgroundJob('MYBundleServicesPublishWorker~publish',
json_encode($parameters)
);
And i have one worker that run infinitely and do the jobs (iterations: 0)
I run it from command line once in background:
nohup php /myproject/app/console gearman:worker:execute MYBundleServicesPublishWorker > /tmp/error_log.txt > /tmp/output_log.txt &
The config look like:
gearman:
# Bundles will parsed searching workers
bundles:
# Name of bundle
MyBundle:
# Bundle name
name: myBundle
# Bundle search can be enabled or disabled
active: true
# If any include is defined, Only these namespaces will be parsed
# Otherwise, full Bundle will be parsed
include:
- Services
- EventListener
# Namespaces this Bundle will ignore when parsing
ignore:
- DependencyInjection
- Resources
# default values
# All these values will be used if are not overwritten in Workers or jobs
defaults:
# Default method related with all jobs
# do // deprecated as of pecl/gearman 1.0.0. Use doNormal
# doNormal
# doBackground
# doHigh
# doHighBackground
# doLow
# doLowBackground
method: doNormal
# Default number of executions before job dies.
# If annotations defined, will be overwritten
# If empty, 0 is defined by default
iterations: 0
# execute callbacks after operations using Kernel events
callbacks: true
# Prefix in all jobs
# If empty name will not be modified
# Useful for rename jobs in different environments
job_prefix: null
# Autogenerate unique key in jobs/tasks if not set
# This key is unique given a Job name and a payload serialized
generate_unique_key: true
# Prepend namespace when callableName is built
# By default this variable is set as true
workers_name_prepend_namespace: true
# Server list where workers and clients will connect to
# Each server must contain host and port
# If annotations defined, will be full overwritten
#
# If servers empty, simple localhost server is defined by default
# If port empty, 4730 is defined by efault
servers:
localhost:
host: 127.0.0.1
port: 4730
doctrine_cache:
providers:
gearman_cache:
type: apc
namespace: doctrine_cache.ns.gearman
my problem is when i run app/console cache:clear and after that job come in the worker crash
its throw error :
PHP Warning:
require_once(/myproject/app/cache/dev/jms_diextra/doctrine/EntityManager_53a06fbf221b4.php):
failed to open stream: No such file or directory in
/myproject/app/cache/dev/appDevDebugProjectContainer.php on line 787
PHP Fatal error: require_once(): Failed opening required
'/myproject/app/cache/dev/jms_diextra/doctrine/EntityManager_53a06fbf221b4.php'
(include_path='.:/usr/share/php:/usr/share/pear') in
/myproject/app/cache/dev/appDevDebugProjectContainer.php on line 787
How can i fix it, i try to change the doctrine bundle cache type: file_system/array/apc
but it did not help
How can i overcome this?
what i am doing wrong?
Thanks in advance
i found the problem, i have in my worker this line :
$this->doctrine->resetEntityManager();
that cause this,
now i am only open connection and close it like:
$em = $this->doctrine->getEntityManager();
$em->getConnection()->connect();
# run publish command
............
# close connection
$em->getConnection()->close();