Error en Creación de Bundle en Symfony 2.8

494 views
Skip to first unread message

Oswaldo Gaitán Araque

unread,
Aug 26, 2017, 1:44:57 AM8/26/17
to symfony-es
Buenas Noches a los integrantes de este grupo:

Reciba un cordial saludo, de antemano les agradezco la ayuda que me puedan brindar soy nuevo con Symfony me lo recomendó un ingeniero para desarrollar, ya programado con php normal, pero nunca he trabajado con Frameworks, ya tengo instalado xampp, symfony 2.8, composer.

Me da la pantalla de que instale correctamente el Symfony, pero cuando creo un Bundle me sale este error "Fatal error: Class 'AppBundle\AppBundle' not found in C:\xampp\htdocs\prueba1\app\AppKernel.php on line 18", he googleado pero la verda no he podido solucionarlo.

Este es mi AppKernel.php

<?php

use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
            new Symfony\Bundle\SecurityBundle\SecurityBundle(),
            new Symfony\Bundle\TwigBundle\TwigBundle(),
            new Symfony\Bundle\MonologBundle\MonologBundle(),
            new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
            new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
            new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
            new AppBundle\AppBundle(),
            new ingresoBundle\ingresoBundle(),
        );

        if (in_array($this->getEnvironment(), array('dev', 'test'), true)) {
            $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
            $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
            $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
            $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
        }

        return $bundles;
    }

    public function registerContainerConfiguration(LoaderInterface $loader)
    {
        $loader->load($this->getRootDir().'/config/config_'.$this->getEnvironment().'.yml');
    }
}

Este es parte del composer.json

{
    "name": "ts1/prueba1",
    "license": "proprietary",
    "type": "project",
    "autoload": {
        "psr-4": {
            "AppBundle\\AppBundle\\": "src/AppBundle",
            "ingresoBundle\\ingresoBundle\\": "src/ingresoBundle"
        },
        "classmap": [
            "app/AppKernel.php",
            "app/AppCache.php"
        ]
    },
    "autoload-dev": {
        "files": [
            "vendor/symfony/symfony/src/Symfony/Component/VarDumper/Resources/functions/dump.php"
        ]
    },

Lo actualice con el comando composer update y sale este otro error:

c:\xampp\htdocs\prueba1>composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 2 installs, 0 updates, 0 removals
  - Installing sensio/generator-bundle (v3.1.6): Loading from cache
  - Installing symfony/phpunit-bridge (v2.8.26): Loading from cache
Generating autoload files
> Incenteev\ParameterHandler\ScriptHandler::buildParametersUpdating the "app/config/parameters.yml" file
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache

Fatal error: Class 'AppBundle\AppBundle' not found in C:\xampp\htdocs\prueba1\app\AppKernel.php on line 18
PHP Fatal error:  Class 'AppBundle\AppBundle' not found in C:\xampp\htdocs\prueba1\app\AppKernel.php on line 18
Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the symfony-scripts event terminated with an exception

  [RuntimeException]
  An error occurred when executing the ""cache:clear --no-warmup"" command:Fatal error: Class 'AppBundle\AppBundle' not found in C:\xampp\htdocs\prueb
  a1\app\AppKernel.php on line 18
  PHP Fatal error:  Class 'AppBundle\AppBundle' not found in C:\xampp\htdocs\prueba1\app\AppKernel.php on line 18
  .
update [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--lock]
 [--no-custom-installers] [--no-autoloader] [--no-scripts] [--no-progress] [--no
-suggest] [--with-dependencies] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader]
 [-a|--classmap-authoritative] [--apcu-autoloader] [--ignore-platform-reqs] [--p
refer-stable] [--prefer-lowest] [-i|--interactive] [--root-reqs] [--] [<packages
>]...

Les agradezco su ayuda de como puedo solucionarlo, gracias.

Atentamente;

OSWALDO GAITAN
Bendiciones!!


Juandy Ocampo

unread,
Aug 26, 2017, 9:19:08 PM8/26/17
to symfony-es
Lo del problema del AppBundle necesitas verlo en services.yml o en el AppBundle.php. Saludos

Isaac Pérez

unread,
Aug 27, 2017, 3:42:16 AM8/27/17
to symfo...@googlegroups.com
Tambien puedes Googlear dentro del grupo (enlace en la firma del correo)

He encontrado una pregunta (y respuesta) parecida en este hilo

Prueba, parece ser que el Class Not Found hace referencia a un mal mapeo de archivos o una configuración incorrecta

--
--
Has recibido este mensaje porque estás suscrito al grupo "symfony-es" de Google Groups.
Para publicar en este grupo, envía un email a symfo...@googlegroups.com
Para darte de baja, envía un email a symfony-es+unsubscribe@googlegroups.com
El resto de opciones puedes encontrarlas en http://groups.google.com/group/symfony-es?hl=es

---
Has recibido este mensaje porque estás suscrito al grupo "symfony-es" de Grupos de Google.
Para cancelar la suscripción a este grupo y dejar de recibir sus mensajes, envía un correo electrónico a symfony-es+unsubscribe@googlegroups.com.
Para acceder a más opciones, visita https://groups.google.com/d/optout.

Germán Figna

unread,
Aug 27, 2017, 6:13:49 AM8/27/17
to symfo...@googlegroups.com
No es necesario que añadas el bundle en el composer.json
Quítalo y comprueba que el fichero AppBundle.php tiene el namespace correcto. El fichero tiene que ser algo así:

namespace AppBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class AppBundle extends Bundle
{
}
--
_____________________________
Germán Figna .-

Oswaldo Gaitán Araque

unread,
Aug 31, 2017, 10:43:25 PM8/31/17
to symfony-es
Buenas Noches Juandy:

Gracias por la respuesta, le cuento que volví a correr el symfony y ahora me arroja este error de un nuevo Bundle que cree:


Fatal error: Class 'inicioBundle\inicioBundle' not found in C:\xampp\htdocs\jesus\app\AppKernel.php on line 19

En src/inicioBundle/Resources/config/services.yml

services:
    inicio.example:
        class: inicioBundle\Example
        arguments: ["@service_id", "plain_value", "%parameter%"]

Estaba con comentarios # y lo retire.

En app/config/services.yml

# Learn more about services, parameters and containers at
parameters:
    #parameter_name: value

services:
    service_name:
        class: AppBundle\Directory\ClassName
        arguments: ['@another_service_name', 'plain_value', '%parameter_name%']

En src/inicioBundle/inicioBundle.php

<?php

namespace inicioBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class inicioBundle extends Bundle
{
}

Le agradecería me indicara en donde estoy haciendo mal, la verdad soy nuevo en Symfony.

Atentamente;

OSWALDO GAITAN ARAQUE
Bendiciones!!

Oswaldo Gaitán Araque

unread,
Aug 31, 2017, 10:53:58 PM8/31/17
to symfony-es
Buenas Noches Isaac Pérez:

Gracias por la respuesta pero no me funciono el comando que dice en el hilo que me envío, ./bin/vendors install --reinstall, no lo ejecuta para la versión de Symfony 2.8, que estoy trabajando, alguna otra idea que me pueda ayudar?

Oswaldo Gaitán Araque

unread,
Aug 31, 2017, 11:15:46 PM8/31/17
to symfony-es
Buenas Noches Germán Figna:

Gracias por su ayuda, revise el AppBundle y esta como sumerse lo escribió, me comenta que no es necesario modificar el composer.json, le relaciono lo que me salio cuando cree el Bundle:

c:\xampp\htdocs\jesus>php app/console generate:bundle


  Welcome to the Symfony bundle generator!


Are you planning on sharing this bundle across multiple applications? [no]:

Your application code must be written in bundles. This command helps
you generate them easily.

Give your bundle a descriptive name, like BlogBundle.
Bundle name: inicioBundle

Bundles are usually generated into the src/ directory. Unless you're
doing something custom, hit enter to keep this default!

Target Directory [src/]:

What format do you want to use for your generated configuration?

Configuration format (annotation, yml, xml, php) [annotation]: yml


  Bundle generation


> Generating a sample bundle skeleton into C:\xampp\htdocs\jesus\app/../src/inic
ioBundle
  created .\app/../src/inicioBundle/
  created .\app/../src/inicioBundle/inicioBundle.php
  created .\app/../src/inicioBundle/Controller/
  created .\app/../src/inicioBundle/Controller/DefaultController.php
  created .\app/../tests/inicioBundle/Controller/
  created .\app/../tests/inicioBundle/Controller/DefaultControllerTest.php
  created .\app/../src/inicioBundle/Resources/views/Default/
  created .\app/../src/inicioBundle/Resources/views/Default/index.html.twig
  created .\app/../src/inicioBundle/Resources/config/
  created .\app/../src/inicioBundle/Resources/config/services.yml
  created .\app/../src/inicioBundle/Resources/config/routing.yml
> Checking that the bundle is autoloaded
FAILED
> Enabling the bundle inside C:\xampp\htdocs\jesus\app\AppKernel.php
  updated .\app\AppKernel.php
OK
> Importing the bundle's routes from the C:\xampp\htdocs\jesus\app\config\routin
g.yml file
  updated .\app/config/routing.yml
OK
> Importing the bundle's services.yml from the C:\xampp\htdocs\jesus\app\config\
config.yml file
  updated .\app/config/config.yml
OK


  The command was not able to configure everything automatically.
  You'll need to make the following changes manually.


- Edit the composer.json file and register the bundle
  namespace in the "autoload" section:

En la última parte dice que editar el composer.json y registrar en namespace, será que existe otro archivo igual que deba modificar? agradezco su valiosa ayuda.

Juandy Ocampo

unread,
Sep 1, 2017, 12:19:27 AM9/1/17
to symfony-es
Oswaldo creo que debes editar el composer.json en esta parte:

"autoload": {
        "psr-4": {
            "": "src/"
        },
        "classmap": [
            "app/AppKernel.php",
            "app/AppCache.php"
        ]
    },

Y luego revisar el AppKernel por los bundles, creo que con eso arreglas tu problema. Saludos

Oswaldo Gaitán Araque

unread,
Sep 19, 2017, 11:41:23 PM9/19/17
to symfo...@googlegroups.com
Buenas Noches Juandy:

Reciba un cordial saludo, gracias por la respuesta si señor efectivamente monte de nuevo todo el Symfony en una máquina virtual y con el cambio que me sugirió funciono perfectamente.

Dios le bendiga grandemente!! por su ayuda.

Juandy Ocampo

unread,
Sep 20, 2017, 12:53:46 AM9/20/17
to symfo...@googlegroups.com
De nada, me alegro que te haya servido. Saludos.
Reply all
Reply to author
Forward
0 new messages