Brent
Brent

Reputation: 2485

ClassNotFoundException Symfony

I'm trying to make my website live but keep getting the same error...I've tried looking everywhere and using everyone solution with no luck.

Error

ClassNotFoundException: Attempted to load class "DestinationAppBundle" from namespace "Destination\AppBundle" in /home/dcms/public/html/dcms/apha/app/AppKernel.php line 19. Do you need to "use" it from another namespace?

AppKernel.php

    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 Symfony\Bundle\AsseticBundle\AsseticBundle(),
        new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
        new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
        new Destination\AppBundle\DestinationAppBundle(),
        new Destination\Auth\HashInterfaceBundle\DestinationHashInterfaceBundle(),
    );

File Structure

src
    Destination
        AppBundle

Any ideas?

Upvotes: 6

Views: 12525

Answers (6)

Hett
Hett

Reputation: 3825

Update composer.json like this:

"psr-4": {
    "AppBundle\\": "src/AppBundle",
    "UserBundle\\": "src/UserBundle"
},

After edit composer.json YOU MUST RUN composer dump-autoload

Upvotes: 4

Ron Fridman
Ron Fridman

Reputation: 304

Symfony uses PSR autoload.

You need to configure autoload in the composer.json file:

"autoload": {
    "psr-4": {
        "": "src/"
    },

This will include all files and folders under the \src folder

Upvotes: 0

Samuel Vicent
Samuel Vicent

Reputation: 1031

If you are sure the namespace and service definition are right you can try:

  • Upgrade Symfony version. I had an strange issue with Symfony 2.8.11, new services added gave me a ClassNotFoundException. Upgrading to 2.8.17 solved it.

  • Try remove app/cache/* contents

  • Check if you are using a pre-generated boostrap cached file without the "--no-dev" option (composer dump-autoload --optimize --no-dev --classmap-authoritative) and launch command again.

Upvotes: 0

Milad Shahbazi
Milad Shahbazi

Reputation: 144

first: check if the file src\Destination\AppBundle\DestinationAppBundle.php does exist

second: open DestinationAppBundle.php and chek if the namespace is Destination\AppBundle

third: check if the classname declaration is the same as the filename (in your case : DestinationAppBundle)

Upvotes: 5

ncrocfer
ncrocfer

Reputation: 2570

What is the namespace in your DestinationAppBundle.php ?

It should be :

<?php
namespace Destination\AppBundle;

Upvotes: 0

Ricardo Simas
Ricardo Simas

Reputation: 230

Verify in AppKernel.php the use of this class DestinationAppBundle

And the namespace in the class DestinationAppBundle

Upvotes: 0

Related Questions