2

I have a working Project on localhost but when I deployed the project I received this error and I have no idea what's causing this to happen.

 MappingException: Class 'PremiumPharma\SystemBundle\Entity\User' does not exist

this is the stacktrace

in /home/sy2/public_html/temp/symfony/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/MappingException.php line 96
at MappingException::nonExistingClass('PremiumPharma\SystemBundle\Entity\User') in /home/sy2/public_html/temp/symfony/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/RuntimeReflectionService.php line 43
at RuntimeReflectionService->getParentClasses('PremiumPharma\SystemBundle\Entity\User') in /home/sy2/public_html/temp/symfony/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php line 267

Edit 1 I did notice some errors in the profiler as it said 5 invalid entities and there were some mapping errors and I got them fixed. After re-uploading I still have the same issue. I also tried to empty the cache but I still receive the same error.

Edit 2

here is my appKernal

<?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 Symfony\Bundle\AsseticBundle\AsseticBundle(),
            new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
            new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
            new PremiumPharma\SystemBundle\PremiumPharmaSystemBundle(),
            new FOS\UserBundle\FOSUserBundle(),
        );

        if (in_array($this->getEnvironment(), array('dev', 'test'))) {
            $bundles[] = new Acme\DemoBundle\AcmeDemoBundle();
            $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(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
    }
}

Edit 3

As per J.Mose last comment it was a unix/windows conflict as my local machine was windows and the server was Unix. I had to rename all files to match exactly the classname.

Tharif
  • 13,794
  • 9
  • 55
  • 77
Seif Sayed
  • 783
  • 2
  • 9
  • 18

3 Answers3

6

Did you deploy an older version on this environment ?

If yes, did you delete all application's files before deploying ? If an older version of an entity doesn't exist in your project anymore (or renamed), it can provoke that kind of mapping error.

Alternatively, check in your AppKernel.php if the bundle with the entity is enabled on all environnment.

Further, if application is deployed on a Unix environnement (against a local Windows), check if your entity's name is exactly the same as the php file (cause Windows is case insensitive)

j-guyon
  • 1,822
  • 1
  • 19
  • 31
  • Yes, I had an older version of this project, and I didn't delete it. but now even if I upload a new version with the server being clean. I still run into the same error. I've edited the question with the app.kernal file. it looks like my bundle is added. – Seif Sayed Aug 17 '14 at 09:11
  • Your AppKernel seems good. Another possiblity if your localhost is Window and your server is Unix : This could come from a mistake of case into the name of an entity or its namespace (because Window is case insensitive). – j-guyon Aug 17 '14 at 09:24
  • I checked and waht you said is true. the server is Unix, and I'm developing on Windows. any ideas how can I fix this. – Seif Sayed Aug 17 '14 at 21:57
  • Well, if it's a uppercase / lowercase mistake, check if the file with the unfound entity is well named ("user.php" instead of "User.php" for example). Same check on the class/namespace name. – j-guyon Aug 18 '14 at 07:41
  • I renamed all the entities to lower case and double checked the names in the controllers and they're all lowercase. Do I have to make the Class name lowercase aswell? and I have to make all the entities lowercase. Can't I use Camel ? – Seif Sayed Aug 18 '14 at 18:52
  • 1
    You can use Camel ! Just be sure that the file is named just like his entity. For example if your entity class name is user, Symfony will search a user.php file. If your class name is User, so the file must be User.php – j-guyon Aug 18 '14 at 18:59
  • Please accept the edited anwser, it will give more visibility for others ;) – j-guyon Aug 18 '14 at 20:48
0

this problem has just happened to me and i have fixed it by adding the vendor name to the directory path in the config.yml file.

Step 5: Configure the FOSUserBundle

app/config/config.yml

fos_user:

db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel'
firewall_name: main
user_class: AppBundle\Entity\User

change the appBundle to Vendor\NameofYourBundle\Entity\User

Mohammed Ramadan
  • 655
  • 7
  • 10
0

This error was show me when I used EasyAdminBundle and FOSUserBundle with Symfony 3.3.x .

The solution is simple: First is necessary verification app/config/config.yml in my case the error was the name of the Bundle:

fos_user:
db_driver: orm # other valid values are 'mongodb' and 'couchdb'
firewall_name: main
user_class: BackendBundle\Entity\User

And after clean of cache:

php bin/console cache:warmup

This was my solution

juanitourquiza
  • 2,097
  • 1
  • 30
  • 52