Symfony 4.1 : You have requested a non-existent service "doctrine" - php

Hello i'm making a new project on symfony 4.1,
i use postgres 10.5 as my SGBD.
i created an entity with the maker bundle of symfony and now i try to make a migration still with the maker bundle with that command :
php bin/console make:migration
here is the stack trace :
In Container.php line 274:
You have requested a non-existent service "doctrine". Did you mean one of these: "console.command.public_alias.doctrine_cache.contains_command", "console.command.public
_alias.doctrine_cache.delete_command", "console.command.public_alias.doctrine_cache.flush_command", "console.command.public_alias.doctrine_cache.stats_command", "consol
e.command.public_alias.doctrine_migrations.diff_command", "console.command.public_alias.doctrine_migrations.execute_command", "console.command.public_alias.doctrine_mig
rations.generate_command", "console.command.public_alias.doctrine_migrations.latest_command", "console.command.public_alias.doctrine_migrations.migrate_command", "conso
le.command.public_alias.doctrine_migrations.status_command", "console.command.public_alias.doctrine_migrations.version_command"?
Exception trace:
Symfony\Component\DependencyInjection\Container->make() at /opt/www/jame/dataneo-erp/vendor/symfony/dependency-injection/Container.php:222
Symfony\Component\DependencyInjection\Container->get() at /opt/www/jame/dataneo-erp/vendor/doctrine/doctrine-migrations-bundle/Command/Helper/DoctrineCommandHelper.php:21
Doctrine\Bundle\MigrationsBundle\Command\Helper\DoctrineCommandHelper::setApplicationHelper() at /opt/www/jame/dataneo-erp/vendor/doctrine/doctrine-migrations-bundle/Command/MigrationsDiffDoctrineCommand.php:34
Doctrine\Bundle\MigrationsBundle\Command\MigrationsDiffDoctrineCommand->execute() at /opt/www/jame/dataneo-erp/vendor/symfony/console/Command/Command.php:251
Symfony\Component\Console\Command\Command->run() at /opt/www/jame/dataneo-erp/vendor/symfony/maker-bundle/src/Maker/MakeMigration.php:78
Symfony\Bundle\MakerBundle\Maker\MakeMigration->generate() at /opt/www/jame/dataneo-erp/vendor/symfony/maker-bundle/src/Command/MakerCommand.php:100
Symfony\Bundle\MakerBundle\Command\MakerCommand->execute() at /opt/www/jame/dataneo-erp/vendor/symfony/console/Command/Command.php:251
Symfony\Component\Console\Command\Command->run() at /opt/www/jame/dataneo-erp/vendor/symfony/console/Application.php:904
Symfony\Component\Console\Application->doRunCommand() at /opt/www/jame/dataneo-erp/vendor/symfony/framework-bundle/Console/Application.php:89
Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand() at /opt/www/jame/dataneo-erp/vendor/symfony/console/Application.php:262
Symfony\Component\Console\Application->doRun() at /opt/www/jame/dataneo-erp/vendor/symfony/framework-bundle/Console/Application.php:75
Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /opt/www/jame/dataneo-erp/vendor/symfony/console/Application.php:145
Symfony\Component\Console\Application->run() at /opt/www/jame/dataneo-erp/bin/console:39
here is the code of some config files :
services.yaml
# This file is the entry point to configure your own services.
# Files in the packages/ subdirectory configure your dependencies.
# 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: 'fr'
services:
autowire: true
autoconfigure: true
public: false
App\:
resource: '../src/*'
exclude: '../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}'
App\Controller\:
resource: '../src/Controller'
tags: ['controller.service_arguments']
config/packages/doctrine.yaml
parameters:
env(DATABASE_URL): ''
doctrine:
dbal:
driver: 'pdo_pgsql'
server_version: '10.5'
charset: utf8mb4
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci
url: '%env(resolve:DATABASE_URL)%'
orm:
auto_generate_proxy_classes: '%kernel.debug%'
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
and my .env
APP_ENV=dev
APP_SECRET=secret
DATABASE_URL="pgsql://erp_dev:My_PASSWORD#127.0.0.1:5432/erp"
MAILER_URL=null://localhost
Edit :
I tried to put "services : public : true" in services.yaml as mentioned in second answer and the result is a new error :
In DefinitionErrorExceptionPass.php line 54:
[Symfony\Component\DependencyInjection\Exception\RuntimeException]
Cannot autowire service "App\Repository\SocieteRepository": argument "$registry" of method "__construct()" refer
ences interface "Symfony\Bridge\Doctrine\RegistryInterface" but no such service exists. Did you create a class t
hat implements this interface?
Exception trace:
Symfony\Component\DependencyInjection\Compiler\DefinitionErrorExceptionPass->processValue() at /opt/www/jame/dataneo-erp/vendor/symfony/dependency-injection/Compiler/AbstractRecursivePass.php:60
Symfony\Component\DependencyInjection\Compiler\AbstractRecursivePass->processValue() at /opt/www/jame/dataneo-erp/vendor/symfony/dependency-injection/Compiler/DefinitionErrorExceptionPass.php:32
Symfony\Component\DependencyInjection\Compiler\DefinitionErrorExceptionPass->processValue() at /opt/www/jame/dataneo-erp/vendor/symfony/dependency-injection/Compiler/AbstractRecursivePass.php:39
Symfony\Component\DependencyInjection\Compiler\AbstractRecursivePass->process() at /opt/www/jame/dataneo-erp/vendor/symfony/dependency-injection/Compiler/Compiler.php:95
Symfony\Component\DependencyInjection\Compiler\Compiler->compile() at /opt/www/jame/dataneo-erp/vendor/symfony/dependency-injection/ContainerBuilder.php:736
Symfony\Component\DependencyInjection\ContainerBuilder->compile() at /opt/www/jame/dataneo-erp/vendor/symfony/http-kernel/Kernel.php:519
Symfony\Component\HttpKernel\Kernel->initializeContainer() at /opt/www/jame/dataneo-erp/vendor/symfony/http-kernel/Kernel.php:123
Symfony\Component\HttpKernel\Kernel->boot() at /opt/www/jame/dataneo-erp/vendor/symfony/framework-bundle/Console/Application.php:65
Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /opt/www/jame/dataneo-erp/vendor/symfony/console/Application.php:145
Symfony\Component\Console\Application->run() at /opt/www/jame/dataneo-erp/bin/console:39
Here is the result of the command
php bin/console debug:container | grep doctrine
console.command.public_alias.doctrine_cache.contains_command alias for "doctrine_cache.contains_command"
console.command.public_alias.doctrine_cache.delete_command alias for "doctrine_cache.delete_command"
console.command.public_alias.doctrine_cache.flush_command alias for "doctrine_cache.flush_command"
console.command.public_alias.doctrine_cache.stats_command alias for "doctrine_cache.stats_command"
console.command.public_alias.doctrine_migrations.diff_command alias for "doctrine_migrations.diff_command"
console.command.public_alias.doctrine_migrations.execute_command alias for "doctrine_migrations.execute_command"
console.command.public_alias.doctrine_migrations.generate_command alias for "doctrine_migrations.generate_command"
console.command.public_alias.doctrine_migrations.latest_command alias for "doctrine_migrations.latest_command"
console.command.public_alias.doctrine_migrations.migrate_command alias for "doctrine_migrations.migrate_command"
console.command.public_alias.doctrine_migrations.status_command alias for "doctrine_migrations.status_command"
console.command.public_alias.doctrine_migrations.version_command alias for "doctrine_migrations.version_command"
doctrine_cache.abstract.apc Doctrine\Common\Cache\ApcCache
doctrine_cache.abstract.apcu Doctrine\Common\Cache\ApcuCache
doctrine_cache.abstract.array Doctrine\Common\Cache\ArrayCache
doctrine_cache.abstract.chain Doctrine\Common\Cache\ChainCache
doctrine_cache.abstract.couchbase Doctrine\Common\Cache\CouchbaseCache
doctrine_cache.abstract.file_system Doctrine\Common\Cache\FilesystemCache
doctrine_cache.abstract.memcache Doctrine\Common\Cache\MemcacheCache
doctrine_cache.abstract.memcached Doctrine\Common\Cache\MemcachedCache
doctrine_cache.abstract.mongodb Doctrine\Common\Cache\MongoDBCache
doctrine_cache.abstract.php_file Doctrine\Common\Cache\PhpFileCache
doctrine_cache.abstract.predis Doctrine\Common\Cache\PredisCache
doctrine_cache.abstract.redis Doctrine\Common\Cache\RedisCache
doctrine_cache.abstract.riak Doctrine\Common\Cache\RiakCache
doctrine_cache.abstract.sqlite3 Doctrine\Common\Cache\SQLite3Cache
doctrine_cache.abstract.void Doctrine\Common\Cache\VoidCache
doctrine_cache.abstract.wincache Doctrine\Common\Cache\WinCacheCache
doctrine_cache.abstract.xcache Doctrine\Common\Cache\XcacheCache
doctrine_cache.abstract.zenddata Doctrine\Common\Cache\ZendDataCache
doctrine_cache.contains_command Doctrine\Bundle\DoctrineCacheBundle\Command\ContainsCommand
doctrine_cache.delete_command Doctrine\Bundle\DoctrineCacheBundle\Command\DeleteCommand
doctrine_cache.flush_command Doctrine\Bundle\DoctrineCacheBundle\Command\FlushCommand
doctrine_cache.stats_command Doctrine\Bundle\DoctrineCacheBundle\Command\StatsCommand
doctrine_migrations.diff_command Doctrine\Bundle\MigrationsBundle\Command\MigrationsDiffDoctrineCommand
doctrine_migrations.execute_command Doctrine\Bundle\MigrationsBundle\Command\MigrationsExecuteDoctrineCommand
doctrine_migrations.generate_command Doctrine\Bundle\MigrationsBundle\Command\MigrationsGenerateDoctrineCommand
doctrine_migrations.latest_command Doctrine\Bundle\MigrationsBundle\Command\MigrationsLatestDoctrineCommand
doctrine_migrations.migrate_command Doctrine\Bundle\MigrationsBundle\Command\MigrationsMigrateDoctrineCommand
doctrine_migrations.status_command Doctrine\Bundle\MigrationsBundle\Command\MigrationsStatusDoctrineCommand
doctrine_migrations.version_command Doctrine\Bundle\MigrationsBundle\Command\MigrationsVersionDoctrineCommand
maker.doctrine_helper Symfony\Bundle\MakerBundle\Doctrine\DoctrineHelper
sensio_framework_extra.converter.doctrine.orm Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter\DoctrineParamConverter
sensio_framework_extra.converter.doctrine.orm.expression_language alias for "sensio_framework_extra.converter.doctrine.orm.expression_language.default"
sensio_framework_extra.converter.doctrine.orm.expression_language.default Symfony\Component\ExpressionLanguage\ExpressionLanguage
Thank you a lot.

Change the following line in your services.yml
services:
public: false
by
services:
public: true

I had the same error when I tried to add unit tests for my custom symfony bundle. In /tests/App/AppKernel.php I have loaded DoctrineBundle:
<?php
namespace App\Tests\App;
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
class AppKernel extends Kernel
{
use MicroKernelTrait;
public function __construct()
{
parent::__construct('test', true);
}
public function registerBundles(): iterable
{
return array(
new FrameworkBundle(),
new DoctrineBundle(),
);
}
protected function configureContainer(ContainerBuilder $containerBuilder, LoaderInterface $loader): void
{
$loader->load(__DIR__.'/config/config.yml');
$loader->load(__DIR__.'/config/services.yml');
}
}
I did not need DB connection so I did not add doctrine configurations, but because doctrine configuration was missing I got this error.
The Solution was to add doctrine configuration for tests /tests/App/config/doctrine.yml:
doctrine:
dbal:
url: '%env(resolve:DATABASE_URL)%'
orm:
auto_generate_proxy_classes: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
mappings:
App:
is_bundle: false
dir: '%kernel.project_dir%/Entity'
prefix: 'MainBundle\Entity'
alias: App
and load it in /tests/App/AppKernel.php:
protected function configureContainer(ContainerBuilder $containerBuilder, LoaderInterface $loader): void
{
$loader->load(__DIR__.'/config/config.yml');
$loader->load(__DIR__.'/config/services.yml');
$loader->load(__DIR__.'/config/doctrine.yml');
}
Note: you will need to configure phpunit.xml.dist to use this AppKernel file.
I needed EntityManager for my tests, for this I had to add doctrine.dbal and doctrine.orm, but just to solve this error doctrine.dbal configuration is enough.

Related

make:entity command: [ERROR] Only annotation mapping is supported by make:entity

When I am trying to create a new doctrine entity in Symfony 5.2 (maker-bundle v1.30.0) I get:
$ php bin/console make:entity
Class name of the entity to create or update (e.g. GrumpyChef):
> test
created: src/Entity/Test.php
created: src/Repository/TestRepository.php
[ERROR] Only annotation mapping is supported by make:entity, but the
<info>App\Entity\Test</info> class uses a different format. If you
would like this command to generate the properties & getter/setter
methods, add your mapping configuration, and then re-run this command
with the <info>--regenerate</info> flag.
The files are generated and they look OK to me. I get the same for existing entities, except for the "created" lines. I have read about similar problems from years ago, but they were related to different namespaces which is not the case here, I am using the default namespace.
I believe the problem is related to an update, because of course it previously (not sure if it was 5.0 or 5.1) worked.
Is there any way to debug the MakerBundle or any idea how to solve this problem?
Thanks.
../config/packages/doctrine.yaml (I do not think I ever touched this):
doctrine:
dbal:
url: '%env(resolve:DATABASE_URL)%'
# IMPORTANT: You MUST configure your server version,
# either here or in the DATABASE_URL env var (see .env file)
#server_version: '5.7'
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
$ php bin/console debug:config doctrine
Current configuration for extension with alias "doctrine"
=========================================================
doctrine:
dbal:
default_connection: default
connections:
default:
url: '%env(resolve:DATABASE_URL)%'
override_url: false
driver: pdo_mysql
logging: true
profiling: true
profiling_collect_backtrace: false
profiling_collect_schema_errors: true
options: { }
mapping_types: { }
default_table_options: { }
slaves: { }
replicas: { }
shards: { }
types: { }
orm:
auto_generate_proxy_classes: true
default_entity_manager: default
entity_managers:
default:
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
mappings:
App:
is_bundle: false
type: annotation
dir: <<root_path>>/src/Entity
prefix: App\Entity
alias: App
mapping: true
query_cache_driver:
type: null
metadata_cache_driver:
type: null
result_cache_driver:
type: null
class_metadata_factory_name: Doctrine\ORM\Mapping\ClassMetadataFactory
default_repository_class: Doctrine\ORM\EntityRepository
quote_strategy: doctrine.orm.quote_strategy.default
entity_listener_resolver: null
repository_factory: doctrine.orm.container_repository_factory
hydrators: { }
filters: { }
proxy_dir: '%kernel.cache_dir%/doctrine/orm/Proxies'
proxy_namespace: Proxies
resolve_target_entities: { }
https://github.com/symfony/maker-bundle/issues/841
symfony/maker-bundle v1.30.1 fixes it.

Symfony table entity has itself recognized as repository as well

New to both Symfony and StackOverflow as an OP.
I'm on a way adding new mysql table entities and repositories on Symfony(4.3.2) and get stuck as I test it.
I really appreciate someone's help.
The error I got was
[2020-07-13 03:25:59] request.CRITICAL: Uncaught PHP Exception RuntimeException: "The "App\Entity\Foo" entity has a repositoryClass set to "App\Repository\Foo", but this is not a valid class. Check your class naming. If this is meant to be a service id, make sure this service exists and is tagged with "doctrine.repository_service"." at /var/www/html/bar_project/vendor/doctrine/doctrine-bundle/Repository/ContainerRepositoryFactory.php line 66 {"exception":"[object] (RuntimeException(code: 0): The \"App\\Entity\\Foo\" entity has a repositoryClass set to \"App\\Repository\\Foo\", but this is not a valid class. Check your class naming. If this is meant to be a service id, make sure this service exists and is tagged with \"doctrine.repository_service\". at /var/www/html/bar_project/vendor/doctrine/doctrine-bundle/Repository/ContainerRepositoryFactory.php:66)"} []
where Foo at /App/Entity/ is an entity for the table foo.
and the problem is that it tries to refer to Foo at App/Repository/ as its repository which doesn't exist, but not FooRepository which exists.
(Updated this paragraph following the comment from Jakumi)
(FooController.php)
$repository = $this->getDoctrine()->getRepository(Foo::class);
(Foo.php)
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Table(name="foo")
* #ORM\Entity(repositoryClass="App\Repository\FooRepository") // *1
*/
class Foo
{
...
(FooRepository.php)
<?php
namespace App\Repository;
use App\Entity\Foo;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Symfony\Bridge\Doctrine\RegistryInterface;
/**
* #method Foo|null find($id, $lockMode = null, $lockVersion = null)
* ...
*/
class FooRepository extends ServiceEntityRepository
{
...
One thing I find mysterious is that the same error log still shows up even if I remove *1.
(I think I have yarn watch and cache clear appropriately working.)
Additional Info 1
(doctrine.yaml)
doctrine:
dbal:
# configure these for your database server
driver: 'pdo_mysql'
server_version: '8.0'
charset: utf8mb4
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci
# dbname:
# host:
# port:
# user:
# password:
url: '%env(resolve:DATABASE_URL)%'
options:
1002: 'SET sql_mode=(SELECT REPLACE(##sql_mode, "ONLY_FULL_GROUP_BY", ""))'
orm:
auto_generate_proxy_classes: true
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
metadata_cache_driver: apcu
result_cache_driver: apcu
query_cache_driver: apcu
connection: ~
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
dql:
string_functions:
group_concat: DoctrineExtensions\Query\Mysql\GroupConcat
date_format: DoctrineExtensions\Query\Mysql\DateFormat

Symfony 4 Doctrine, creating Entities from database table

New to Symfony here
I am following this tutorial about mapping db tables to entities. I created the blog_post and blog_comment tables in my db.
I tried running this php bin/console doctrine:mapping:import --force AppBundle xml which spit out the following error.
Bundle "AppBundle" does not exist or it is not enabled. Maybe you forgot to
add it in the registerBundles() method of your App\Kernel.php file?
My doctrine.yaml is pretty much out of the box.
Doctrine.yaml
doctrine:
dbal:
# configure these for your database server
driver: 'pdo_mysql'
server_version: '5.7'
charset: utf8mb4
# With Symfony 3.3, remove the `resolve:` prefix
url: '%env(resolve:DATABASE_URL)%'
orm:
auto_generate_proxy_classes: '%kernel.debug%'
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
mappings:
App:
is_bundle: true
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
I created the App.php Class under src/Entity/ and added a line under bundles.php but still get an error. The line I added on bundles.php is
App\Entity\App::class=>['all' => true], since that is the defined namespace of my App.php class.
Another error I get is
PHP Fatal error: Uncaught
Symfony\Component\Debug\Exception\ClassNotFoundException: Attempted to load
class "App" from namespace "App\Entity\App".
Did you forget a "use" statement for another namespace? in
/var/www/html/quick_tour/src/Kernel.php:32
you must use App rather than AppBundle on Symfony 4
Found similar situation to mine in here as well.
Since Symfony 4 Use App instead of Appbundle

Configuring DoctrineExtensions-Taggable in Symfony fullstack with config.yml

I am having difficulty configuring the Doctrine Extension Taggable provided here:
https://github.com/FabienPennequin/DoctrineExtensions-Taggable
My project is using Symfony 2 Fullstack and my configuration is using yaml while my doctrine entities are using annotation. I installed DoctrineExtensions using composer. Adding "fpn/doctrine-extensions-taggable": "dev-master" to the require section on composer.json and then running composer update. This installed without issue.
I then become lost at this section: https://github.com/FabienPennequin/DoctrineExtensions-Taggable#setup-doctrine
I understand that the metadata is a Doctrine Entity however as previously mentioned I am using yaml for my symfony configuration as well as entity managers. Here is the excerpt from my config.yml file:
# Doctrine Configuration
doctrine:
dbal:
default_connection: default
connections:
default:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
orm:
default_entity_manager: main
auto_generate_proxy_classes: "%kernel.debug%"
entity_managers:
main:
connection: default
mappings:
VendorMainBundle:
prefix: Vendor\MainBundle\Entity
taggable:
connection: default
mappings:
taggable:
type: xml
prefix: DoctrineExtensions\Taggable\Entity
dir: %kernel.root_dir%/../vendor/fpn/doctrine-extensions-taggable/metadata
However, when I run php app/console doctrine:mapping:info --em=taggable I get the error:
[Exception]
You do not have any mapped Doctrine ORM entities according to the current configuration. If you have entities or mapping files you should check your mapping configuration for errors.
Should the above command show the mappings described in the xml files?
Thereby allowing me to update the schema in the database?
I used this documenation as reference for the config.yml file: http://symfony.com/doc/current/reference/configuration/doctrine.html#mapping-configuration
I also added this under the config.yml in order to setup the TagListener. Is this correct?
services:
taggable:
class: DoctrineExtensions\Taggable\TagListener
EDIT [#Grimv01k]:
The TagListener requires an argument passed that is an instance of the TagManager Object. I created another service to handle that as follows and passed it to the TagListener:
tag.manager:
class: DoctrineExtensions\Taggable\TagManager
tags:
- { name: doctrine.event_subscriber, connection: default }
arguments:
entity.manager: #doctrine.orm.entity_manager
taggable:
class: DoctrineExtensions\Taggable\TagListener
arguments:
manager: #tag.manager
The TagManager requires an argument of the entityManager however by doing so results in error:
[Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException]
Circular reference detected for service "doctrine.dbal.default_connection", path: "doctrine.dbal.default_connection".
Across the web it's recommended to resolve this error by passing #service_container and in the constructor of the object pull out the entity_manager, however being a vendor I'd prefer not to modify their code. Is there another way?
Just guess: maybe that happens becuse you haven't got tags applied in service, and Doctrine doesn't use this in your complier pass. Try to do it like this:
services:
taggable:
class: DoctrineExtensions\Taggable\TagListener
tags:
- { name: doctrine.event_subscriber, connection: default }

Symfony2 - Fatal error with Bundles

I've got the error [Solution at the end of the question]
Fatal error: Class 'symblog\Blogger\BlogBundle\SymblogBundle' not found in
/var/www/Symfony/app/AppKernel.php on line 20
I founded the question How to install or integrate bundles in Symfony2, but the solutions given didn't help me, because I already did what is suggested there. I'm following the tutorial symblog.co.uk except that I created at
app/config/routing.yml
a
*.php resource
Thanks in advance!
I have to add that while registering the bundle by console I've got the error
The command was not able to configure everything automatically.
You must do the following changes manually.
And the instructions:
- Edit the app/autoload.php file and register the bundle
namespace at the top of the registerNamespaces() call:
'symblog\Blogger\BlogBundle' => '/var/www/Symfony/blog',
which I followed.
AppKernel.php
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
//..
new symblog\Blogger\BlogBundle\SymblogBundle(),
);
/app/config/routing.yml
SymblogBundle:
resource: "#SymblogBundle/Resources/config/routing.php"
prefix: /
As requested: /app/config/config.yml
imports:
- { resource: parameters.ini }
- { resource: security.yml }
framework:
#esi: ~
#translator: { fallback: %locale% }
secret: %secret%
charset: UTF-8
router: { resource: "%kernel.root_dir%/config/routing.yml" }
form: true
csrf_protection: true
validation: { enable_annotations: true }
templating: { engines: ['twig'] } #assets_version: SomeVersionScheme
session:
default_locale: %locale%
auto_start: true
# Twig Configuration
twig:
debug: %kernel.debug%
strict_variables: %kernel.debug%
# Assetic Configuration
assetic:
debug: %kernel.debug%
use_controller: false
# java: /usr/bin/java
filters:
cssrewrite: ~
# closure:
# jar: %kernel.root_dir%/java/compiler.jar
# yui_css:
# jar: %kernel.root_dir%/java/yuicompressor-2.4.2.jar
# Doctrine Configuration
doctrine:
dbal:
driver: %database_driver%
host: %database_host%
port: %database_port%
dbname: %database_name%
user: %database_user%
password: %database_password%
charset: UTF8
orm:
auto_generate_proxy_classes: %kernel.debug%
auto_mapping: true
# Swiftmailer Configuration
swiftmailer:
transport: %mailer_transport%
host: %mailer_host%
username: %mailer_user%
password: %mailer_password%
jms_security_extra:
secure_controllers: true
secure_all_services: false
[Edit] The solution was very easy after the answer from #Clamidity that the bundles usually are located at src/Blogger/SymBlogBundle/BloggerSymBlogBundle.php
While the configuration using the console it saked about the location of the bundle and the default was /../src but I changed to /../blog. And of course it won't work, Symfony was looking into the wrong location. What I did was to move the folders inside /blog to /src and everything went fine.
There are a few things that it could be. I'll just cover anything I can think of.
Generally bundles are placed in the src folder. So the path to your bundle should look like this.
src/Blogger/SymBlogBundle/BloggerSymBlogBundle.php
(Notice that the bundle name follows the file name convention)
Inside of the BloggerSymBlogBundle.php make sure you have something similar to the following:
<?php
namespace Blogger\SymBlogBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class BloggerSymBlogBundle extends Bundle
{
}
(Notice that the same name convention is also followed here)
In your autoload.php the namespace that should be registered is the "Blogger" part of the name/path to your bundle. This is because the bundle itself resides in the Blogger folder:
'Blogger' => __DIR__.'/../src',
(Notice that the folder listed is the parent of the Blogger folder)
Now in the AppKernel.php register the bundle according the namespace your set up and registered:
new Blogger\SymBlogBundle\BloggerSymBlogBundle(),
*Note - Your resources and references to this bundle with the above configuration would be
BloggerSymBlogBundle
so your php routing would be called by using:
#BloggerSymBlogBundle/Resources/config/routing.php
There are different solution.
Clear the app/cache/(prod|dev) folder. When you have edited the Appkernel and autoload.
Fatal error: Class 'symblog\Blogger\BlogBundle\SymblogBundle' not found in
/var/www/Symfony/app/AppKernel.php on line 20
Here are now different Problems:
Look to the SymblogBundle.php in the Bundle Folder and look which namespace they use. Perhaps its really an uppercase ("S") like #kuba said.
The Class file is not in the folder or you have no rights to the folder that the interpreter can load the file.
I think your autoload.php is not correct.
'Avalanche' => __DIR__.'/../vendor/bundles',
This is the common way to register an Namespace. In your case it have to be
'Symlog' => '/var/www/Symfony/blog',
Here are the instructions from the "BloggerBundle" I hope its the correct one
There you can see the your autoload its not correct the Namespace is "Blogger".

Categories