PHP Fatal error: Class 'Application\Sonata\MediaBundle\ApplicationSonataMediaBundle' not found in /var/www/znata.com/app/AppKernel.php on line 47
Asked Answered
A

7

13

i followed this doc to install SonataMediaBundle but i got this error:

PHP Fatal error:  Class 'Application\Sonata\MediaBundle\ApplicationSonataMediaBundle' not found in /var/www/znata.com/app/AppKernel.php on line 47

After using the sonata command t generate the app:

php app/console sonata:easy-extends:generate SonataMediaBundle

new directory was generated under:

apps/Application/Sonata/MediaBundle

everything was done but when i registred the generated application in my AppKernel.php i got that error.

public function registerbundles()
{
    return array(
        ...
        new Application\Sonata\MediaBundle\ApplicationSonataMediaBundle(),
        ...
    );
}

Have you any idea how to fix this issue ?

Afterlife answered 5/9, 2012 at 0:4 Comment(1)
Can you describe exactly the path of your bundle?Lunnete
A
9

By default project root directory is not in the autoload path, only "src" dir. You can use

php app/console sonata:easy-extends:generate --dest=src SonataMediaBundle

to generate bundle in the src or simple copy it to the src.

Ancelin answered 7/9, 2012 at 21:8 Comment(0)
A
6

After debug this problem, i found that the namspace Application is not registred.

In SF2.0, the documentation said that we should register this namespace like:

<?php
$loader->registerNamespaces(array(
    ...
    'Application'   => __DIR__,
    'Imagine'       => __DIR__.'/../vendor/imagine/lib',
    'Gaufrette'     => __DIR__.'/../vendor/gaufrette/src',
    'Buzz'          => __DIR__.'/../vendor/buzz/lib',
    ...
));

but in SF2.1 they did talked about this.

So i registred the namespace Application in autoload.php and it works fine.

so, the autoload.php look like this:

<?php

// file: app/autoload.php

use Doctrine\Common\Annotations\AnnotationRegistry;
$loader = require __DIR__.'/../vendor/autoload.php';

//custom for Application
$loader->add("Application", __DIR__);


// intl
if (!function_exists('intl_get_error_code')) {
    require_once __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs/functions.php';

    $loader->add('', __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs');
}

AnnotationRegistry::registerLoader(array($loader, 'loadClass'));

return $loader;

With this new config everything is fine.But in SF2.0, they talked also about "Imagine", "Guffrette" and "Buzz" namespaces. So perhapes, when using them, we should register them also like Application namespace.

I hope that this helps you.

Afterlife answered 5/9, 2012 at 18:39 Comment(0)
P
1

Using composer I did this in composer.json: "autoload": { "psr-0": { "": "src/", "Application": "app/" } },

I added the mapping "Application": "app/". And then run composer update

This generated extra autoloading needed.

Pothole answered 3/3, 2014 at 12:19 Comment(0)
C
1
  1. inside your composer.json file, have:

    "autoload": {
        "psr-4": {
            "AppBundle\\": "src/AppBundle",
            "Application\\": "src/Application"
        },
    }
    
  2. do a simple:

    composer dump-autoload
    

    to re-generate the autoload files.

Congruent answered 4/4, 2018 at 10:57 Comment(1)
thanks perfect, but i prefer keeping bundle logic : "Application\\": "src/Application" --> "Application\\Sonata\\UserBundle\\": "src/Application/Sonata/UserBundle"Zollie
U
0
new Application\Sonata\MediaBundle\MediaBundle(),

or

new Application\Sonata\MediaBundle\SonataMediaBundle(),
Utilize answered 5/9, 2012 at 0:18 Comment(0)
S
0

As skonsoft mentioned, you need to load the namespaces in autoload.php. I had the same issue with FOQ.Elastica and resolved it by adding the following.

$loader->add('FOQ', __DIR__.'/../vendor/bundles');

Solley answered 25/2, 2013 at 22:53 Comment(0)
H
0

You can also use your app namespace prefix so the package falls under your namespace

bin/console sonata:easy-extends:generate --dest=src SonataMediaBundle --namespace_prefix=App

Hyperbolic answered 22/4, 2018 at 18:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.