I got this error while I configured Knp paginator Bundle with Symfony 2.4
ERROR :
ClassNotFoundException: Attempted to load class "KnpPaginatorBundle" from namespace "Knp\Bundle\PaginatorBundle" in D:\Projects\wamp\www\Stutorial\app\AppKernel.php line 29. Do you need to "use" it from another namespace?
I followed this steps to install Knp paginator Bundle.
# Install Knp components
git clone git://github.com/KnpLabs/knp-components.git vendor/knp-components
# Install knp paginator bundle
git clone git://github.com/KnpLabs/KnpPaginatorBundle.git vendor/bundles/Knp/Bundle/PaginatorBundle
My config.yml file:
knp_paginator:
page_range: 5 # default page range used in pagination control
default_options:
page_name: page # page query parameter name
sort_field_name: sort # sort field query parameter name
sort_direction_name: direction # sort direction query parameter name
distinct: true # ensure distinct results, useful when ORM queries are using GROUP BY statements
template:
pagination: KnpPaginatorBundle:Pagination:sliding.html.twig # sliding pagination controls template
sortable: KnpPaginatorBundle:Pagination:sortable_link.html.twig # sort link template
I added two lines in my autoload_namespaces.php
'Knp\\Component' => array($vendorDir.'/knp-components/src'),
'Knp\\Bundle' => array($vendorDir.'/bundles'),
And this line to AppKernel.php file
new Knp\Bundle\PaginatorBundle\KnpPaginatorBundle(),
Move your plugin folder to vendor/knplabs/knp-paginator-bundle/, so now the real path would be: vendor/knplabs/knp-paginator-bundle/Knp/Bundle/PaginatorBundle/.
Related
I want to configure the Doctrine bundle to have a DBAL connection. For some reason the configuration needs a bit of logic to retrieve. I tried to use a container extension and then a compiler pass to execute the logic while the container is compiled and store the configuration as container parameters.
During my attempts, I registered the extension and compiler pass like this in the Kernel class:
protected function build(ContainerBuilder $container)
{
// Those lines weren't there at the same time
$container->registerExtension(new MyCustomExtension());
$container->addCompilerPass(new MyCustomCompilerPass());
}
It seemed to work well as I could see my parameters in the console:
# ./bin/console debug:container --parameters
Symfony Container Parameters
============================
------------------------------------------------------------- ------------------------------------------------------------------------
Parameter Value
------------------------------------------------------------- ------------------------------------------------------------------------
...
some.prefix.host some-mariadb-host
some.prefix.dbname some-database-name
...
The problem is that when I try to use those parameters in my config/packages/doctrine.yaml I get an error on my next console command:
doctrine:
dbal:
driver: pdo_mysql
host: '%some.prefix.host%'
dbname: '%some.prefix.dbname%'
# ...
# ./bin/console debug:container --parameters
In ParameterBag.php line 98:
You have requested a non-existent parameter "some.prefix.host".
I am using Symfony 5.3 and Doctrine bundle 2.4.
Why do my parameters seem inaccessible for 3rd party bundle configuration ?
How can I make this work ?
Is there a better way to achieve this ?
I think the Doctrine bundle configuration gets processed before my compiler pass can declare the parameters. It probably can't be solved using the DependencyInjection component.
Solved it by importing a PHP configuration file in the services.yaml:
imports:
- { resource: my_custom_file.php }
With the following content:
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return function(ContainerConfigurator $configurator) {
// My specific logic
// Saving the configuration as parameters
$configurator->parameters()->set('some.prefix.host', $host);
$configurator->parameters()->set('some.prefix.dbname', $dbname);
// ...
};
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.
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
I am trying to begin my education of symfony 2 and started with it's tutorial. One of first things I tried was to install symfony 2 and configure it.
When I try to access http://127.0.0.1:8000/, I am getting an incomplete site with the following error:
ERROR - Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException: "No route found for "GET /"" at /home/spectator/webprojects/cls/app/cache/dev/classes.php line 2059
Things I have tried so far:
clearing cache (php app/console cache:clear --env=prod --no-debug)
recursively changing permissions to folder cls (symfony 2 folder) to
775 and even 777 (for diagnostics purposes)
adding "/" route to routing.yml and routing_dev.yml
reinstalling and
re-chmod symfony 2.
Try http://localhost:8000/app/example
Fresh installation has no routes for the root path "/"
first you need to set a default route
edit the routing.yml
app/config/routing.yml
app:
resource: #AppBundle/Controller/ # bundle name / Controller name
type: annotation # type of routing or
# app/config/routing.yml # file routing
app:
resource: #AppBundle/Controller/
prefix: /
you can learn more in http://symfony.com/doc/current/book/routing.html
The default installation does not come with a default route for "/".
The example controller only defines a route of
#Route("/app/example", name="homepage")
In the past, a fresh Symfony installation also included some simple demo code to learn how does the framework work. A few months ago we decided to change this behavior by the following:
A fresh Symfony installation no longer contains any demo code.
A new "Symfony Demo Application" has been published for people learning the framework (read more about this demo application).
If you use the Symfony Installer, you should do the following:
When learning Symfony, execute the symfony demo command
When creating a new Symfony project, execute the symfony new my_project command
I had the same problem. Just add <?php in the top of the file. Looks like if we don't specify it s
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?