I'm currently working on an application involving the dynamic router. To customise the url generator I followed the documentation found here. Unfortunately it doesn't work, the following exception occurs:
InvalidConfigurationException in ArrayNode.php line 312:
Unrecognized option "url_generator" under "cmf_routing.dynamic"
This is the relevant part of my config.yml:
# CMF Routing Configuration
cmf_routing:
cmf_routing:
routers_by_id:
router.default: 200
cmf_routing.dynamic_router: 100
dynamic:
enabled: true
route_provider_service_id: collab.routing.route_provider
url_generator: collab.routing.url_generator
and for reference, this is the part of services.yml:
collab.routing.route_provider:
class: CollaborationBundle\Routing\RouteProvider
arguments:
- "#annotation_reader"
- "#doctrine.orm.entity_manager"
- "#module.provider"
collab.routing.url_generator:
class: CollaborationBundle\Routing\UrlGenerator
What is the right way to use a custom url generator?
This feature is only available in version 1.4 of RoutingBundle, which is not yet released. You can already start to use it with
symfony-cmf/routing-bundle: 1.4.*#dev
The release should happen in the next days, and we don't expect many changes for 1.4 anymore, so this should be pretty safe.
Related
How can I completely disable the cache in Symfony 5.2?
I use PHP config file (services.php) and not the yaml ones.
In the docs, I cannot find anything matching.
Try configuring the two pools that are always enabled by default to use the Symfony\Component\Cache\Adapter\NullAdapter
framework:
cache:
app: cache.adapter.null
system: cache.adapter.null
services:
cache.adapter.null:
class: Symfony\Component\Cache\Adapter\NullAdapter
arguments: [~] # small trick to avoid arguments errors on compile-time.
https://symfony.com/doc/current/cache.html#configuring-cache-with-frameworkbundle
https://stackoverflow.com/a/46898727/6127393
I recently deep dived into JMS Serializer and although I like it how the package makes a lot of things convenient for the developer in serialisation/deserialisation but there is a major lack of documentation around available options in the package.
I am trying to resolve a virtual property using expressions and I am getting following error.
The property expression_prop on MyPackageName\\SubPackage\\ClassZ requires the expression accessor strategy to be enabled.
Note: the class path has been changed to dummy path.
Here's the YAML config part for the property I am trying to create
virtual_properties:
expression_prop:
exp: object.isUnCategorized()
serialized_name: is_categorized
groups: [tr_view]
type: boolean
And here's the YAML config part of JMS serializer in app/config.yaml
jms_serializer:
metadata:
auto_detection: true
directories:
accounting-process:
namespace_prefix: "DummyBundleName\\SubPAth\\Application\\DTO"
path: "%kernel.root_dir%/../src/path-to-config-directory"
Note the absolute path has again been replaced due to sensitivity of it.
It's necessary to install ExpressionLanguage Component
Command for symfony 3.4:
composer require symfony/expression-language:^3.4
Background: we're using Symfony 3.1 + Doctrine 2.5.5 + symfony doctrine bundle.
While trying to enable second level caching for our entities, we have encountered the following issue. If we use NONSTRICT_READ_WRITE, everything works fine. However, when we tried to use READ_WRITE, we got the following error
0)
Type error: Argument 2 passed to Doctrine\ORM\Cache\Persister\Entity\ReadWriteCachedEntityPersister::__construct() must be an instance of Doctrine\ORM\Cache\ConcurrentRegion, instance of Doctrine\ORM\Cache\Region\DefaultRegion given, called in vendor/doctrine/orm/lib/Doctrine/ORM/Cache/DefaultCacheFactory.php on line 133
As far as I understood, we need to actually implement our own version of ConcurrentRegion and CacheFactory to make it work (FileLockRegion does not suit us due to its usage of file system to handle cache locks). So I wrote those implementations, but the main issue now lies in following: I cannot find where to put my custom factory class' name in the configuration. We have tried the following locations in config:
1)
doctrine:
orm:
auto_generate_proxy_classes: "%kernel.debug%"
default_entity_manager: master
second_level_cache:
default_cache_factory:
class: AppBundle\Cache\MyCacheFactory
This fails due to
Unrecognized option "second_level_cache" under "doctrine.orm"
even though in our other project using Symfony 2.8 option "second_level_cache" does not throw any errors.
So we went to doctrine bundle code and found the following node description (vendor/doctrine/doctrine-bundle/DependencyInjection/Configuration.php:492)
->arrayNode('second_level_cache')
->children()
->append($this->getOrmCacheDriverNode('region_cache_driver'))
->scalarNode('region_lock_lifetime')->defaultValue(60)->end()
->booleanNode('log_enabled')->defaultValue($this->debug)->end()
->scalarNode('region_lifetime')->defaultValue(0)->end()
->booleanNode('enabled')->defaultValue(true)->end()
->scalarNode('factory')->end()
->end()
So we decided we should try this config in our master entity manager section:
2)
second_level_cache:
region_cache_driver:
type: memcache
enabled: true
log_enabled: true
factory: AppBundle\Cache\MyCacheFactory
regions:
hour_region:
lifetime: 3600
However, even though this config is considered valid, when we actually try to access the entity with configured caching, we get the error 0), which makes us think that this option is being ignored by doctrine/symfony.
Is there any way to do it via .yml config at all? Doctrine docs only propose to implement CacheFactory and provide a PHP code example, but it's still quite unclear where should this PHP code go, even if we decide to abandon the idea of putting our class in .yml config and go the PHP way.
Use type - filelock for configurate FilelockRegion
regions:
default:
cache_driver:
type: service
id: 'Doctrine\Common\Cache\RedisCache'
lifetime: 3600
type: filelock
I'm getting the following exception:
InvalidConfigurationException: The child node "clients" at path "snc_redis" must be configured.
I use Symfony 2.3 SncRedisBundle 1.1.x-dev
In config.yml I have
clients:
default:
type: predis
alias: default
dsn: redis://localhost
logging: %kernel.debug%
And I've followed the docs here for installation...
Any idea what would cause this ?
The bundle is looking for configuration values under snc_redis root (as you can see here), which you did not provide.
Now, all this wouldn't normally be a problem, but the clients child node is mandatory (as you can see here), which causes the error above.
Simply make the root configuration node in your config.yml to be snc_redis and the problem will go away. You probably simply missed it when doing copy-paste.
I'm using Symfony2 with the KnpMenuBundle installed as submodules and using the service configuration method.
When calling the page with the menu in the layout using:
{{ knp_menu_render('main') }}
I get the error:
An exception has been thrown during the rendering of a template ("The
menu "main" is not defined.") in CCGlobalBundle::layout.html.twig
My services.yml file (is parsed in the load() method of the CCGlobalExtension.php bundle class) seems to be being called as intentional errors in it cause further code errors:
# src/CC/GlobalBundle/Resources/Config/services.yml
services:
cc_global.menu_builder:
class: CC\GlobalBundle\Menu\MenuBuilder
arguments: ["#knp_menu.factory"]
cc_global.menu.main:
class: Knp\Menu\MenuItem # the service definition requires setting the class
factory_service: cc_global.menu_builder
factory_method: createMainMenu
arguments: ["#request"]
scope: request # needed as we have the request as a dependency here
tags:
- { name: knp_menu.menu, alias: main }
And my main /app/config/config.yml file contains the knp_menu: directive:
knp_menu:
twig:
template: knp_menu.html.twig
templating: false # if true, enables the helper for PHP templates
default_renderer: twig # The renderer to use, list is also available by default
There is the same question but no specific solution that worked here: Symfony2 - KnpMenuBundle: Fatal exception in service container
Does anyone know what could be the problem (also checked the Git issues) for this?
I ran into this issue, but found this exception "The menu 'main' is not defined" was thrown because I had not registered the service of MyCompany/MyBundle/Resources/config/services.yml in app/config/config.yml. Fixed like this:
http://symfony.com/doc/current/book/service_container.html
# app/config/config.yml
imports:
- { resource: "#MyCompanyMyBundle/Resources/config/services.yml" }
A code error was introduced to the Git. The git issue is here: https://github.com/KnpLabs/KnpMenuBundle/issues/89
The change for others looking was line 28 of the /vendor/bundles/Knp/Bundle/MenuBundle/DependencyInjection/KnpMenuExtension.php should have read:
$container->getDefinition(sprintf('knp_menu.menu_provider.%s', $builder))->addTag('knp_menu.provider');
while the incorrect code read:
$container->getDefinition(sprintf('knp_menu.menu_provider.%s', $builder))->addTag('knp_menu.menu_provider');
Note 'provider' vs. '*menu_provider*'