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.
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)
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
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
Related
I have a project in symfony 3.4 then I tried to upgrade to symfony 4 /flex.
the problem is in my code there a 3 bundles TBAdminBundle, TBPlatformBundle and TBSecurityBundle.
Also for each bundle there Extension class exemple.
class TBPlatformExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new PlatformConfiguration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
if (!in_array(strtolower($config['db_driver']), array('custom', 'mongodb', 'orm'))) {
throw new \InvalidArgumentException(sprintf('Invalid db driver "%s".', $config['db_driver']));
}
if ('custom' !== $config['db_driver']) {
$loader->load(sprintf('%s.yml', $config['db_driver']));
$def = new Definition('Doctrine\ORM\EntityManager', array('%tb_notification.model_manager_name%'));
$def->setPublic(false);
if (method_exists($def, 'setFactory')) {
$def->setFactory(array(new Reference('doctrine'), 'getManager'));
} else {
// To be removed when dependency on Symfony DependencyInjection is bumped to 2.6
$def->setFactoryService('doctrine');
$def->setFactoryMethod('getManager');
}
$container->setDefinition('tb_notification.entity_manager', $def);
}
foreach (array('form', 'command', 'events') as $basename) {
$loader->load(sprintf('%s.yml', $basename));
}
$container->setParameter('tb_notification.model_manager_name', $config['model_manager_name']);
$container->setParameter('tb_notification.form.notification.type', $config['form']['notification']['type']);
$container->setParameter('tb_notification.form.notification.name', $config['form']['notification']['name']);
$container->setParameter('tb_trip.form.trip.type', $config['form']['trip']['type']);
$container->setParameter('tb_trip.form.trip.name', $config['form']['trip']['name']);
$container->setParameter(
'tb_notification.form.delete_notification.type',
$config['form']['delete_notification']['type']
);
$container->setParameter(
'tb_notification.form.delete_notification.name',
$config['form']['delete_notification']['name']
);
$container->setParameter('tb_trip.form.trip.update_trip.type', $config['form']['update_trip']['type']);
$container->setParameter('tb_trip.form.trip.update_trip.name', $config['form']['update_trip']['name']);
$container->setParameter('tb_action.form.action.type', $config['form']['action']['type']);
$container->setParameter('tb_action.form.action.name', $config['form']['action']['name']);
$container->setParameter('tb_place.form.place.type', $config['form']['place']['type']);
$container->setParameter('tb_place.form.place.name', $config['form']['place']['name']);
$container->setParameter('tb_action_privacy.form.action.type', $config['form']['privacy']['type']);
$container->setParameter('tb_action_privacy.form.action.name', $config['form']['privacy']['name']);
$container->setParameter('tb_notification.model.notification.class', $config['class']['model']['notification']);
$container->setParameter('tb_trip.model.trip.class', $config['class']['model']['trip']);
$container->setParameter('tb_like.model.like.class', $config['class']['model']['like']);
$container->setParameter('tb_helpful.model.helpful.class', $config['class']['model']['helpful']);
$container->setParameter('tb_action.model.action.class', $config['class']['model']['action']);
$container->setParameter('tb_budget.model.class', $config['class']['model']['budget']);
$container->setParameter('tb_action.model.action_privacy_policy.class', $config['class']['model']['privacy']);
$container->setParameter('tb_rating.model.rating.class', $config['class']['model']['vote']);
$container->setParameter('tb_place.model.place.class', $config['class']['model']['place']);
$container->setParameter('tb_destination.model.destination.class', $config['class']['model']['destination']);
// parameters for hydrating object with doctrine
$container->setParameter('tb_action.hydrate.action', $config['hydrate']['action']);
$container->setParameter('tb_google.key', $config['google']['key']);
$container->setParameter('compare_text.default_percent', $config['compare']['text']);
$container->setAlias('tb_trip.manager.trip', $config['service']['manager']['trip']);
$container->setAlias('tb_like.manager.post', $config['service']['manager']['like']);
$container->setAlias('tb_helpful.manager.post', $config['service']['manager']['helpful']);
$container->setAlias('tb_budget_manager', $config['service']['manager']['budget']);
$container->setAlias('tb_place_manager', $config['service']['manager']['place']);
$container->setAlias('tb_destination_manager', $config['service']['manager']['destination']);
$container->setAlias('tb_compare_string', 'similar_text.manager');
$container->setAlias('foursquare.manager', 'foursquare.manager.default');
$container->setAlias('tb_action.form_factory', $config['service']['form_factory']['action']);
$container->setAlias('tb_place.form_factory', $config['service']['form_factory']['place']);
$container->setAlias('tb_action_privacy.form_factory', $config['service']['form_factory']['privacy']);
$container->setAlias(
'tb_notification.form_factory.notification',
$config['service']['form_factory']['notification']
);
$container->setAlias('tb_trip.form_factory', $config['service']['form_factory']['trip']);
$container->setAlias(
'tb_notification.form_factory.notification_delete',
$config['service']['form_factory']['delete_notification']
);
$container->setAlias('tb_action.customer_repository', 'tb_action.customer_repository_default');
$container->setAlias('tb_notification.customer_repository', 'tb_notification.customer_repository_default');
$container->setAlias('tb_trip.customer_repository', 'tb_trip.customer_repository_default');
}
}
According to documentation
"In Symfony versions prior to 4.0, it was recommended to organize your own application code using bundles. This is no longer recommended and bundles should only be used to share code and features between multiple applications."
I know this it's no more possible with symfony4/flex
How can I rewrite this to match with flex configuration?
thanks
My suggestion is to migrate progressively your bundles.
1. Put the bundle in the src of your SF4 application like this :
src/
Bundle/
TBAdminBundle
TBPlatformBundle
TBSecurityBundle
Command
Controller
Entity
...
2. Use Composer PSR-4 to autoload them (composer.json)
"autoload" : {
"psr-4" : {
"App\\" : "src/",
"TBAdminBundle\\" : "src/Bundle/TBAdminBundle/",
"TBPlatformBundle\\" : "src/Bundle/TBPlatformBundle/",
"TBSecurityBundle\\" : "src/Bundle/TBSecurityBundle/",
...
3. Exclude them from App Services autoload (config/services.yaml)
App\:
resource: '../src/*'
# you can exclude directories or files
# but if a service is unused, it's removed anyway
exclude: '../src/{Entity,Migrations,Repository,Bundle}'
4. Validate the new installation/configuration
Although SF4 is bundle less for core App application, it supports bundle ... Just check that you resolve all deprecated functions from those bundles
5. Start progressive migration of your bundles code:
As Hint :
Rework your config/parameters to use ENV, and services.yaml parameters
So you can transfer most config variables/parameters to the App level and easily share them ...
All your services definitions can be moved from Extention classes into services.yaml for simplicity and easy maintenance.
You will degrease bundles code as time go and you gain experience with the new SF4 services usability and orientations.
That note tells you that it is no longer a recommendation but it doesn't mean that you should refactor your code completely. If you already have your code packed as bundles you should only remove deprecated code. In general it is a good idea to pack your code in bundles only if it is reusable across projects.
I just can't figure this out.
I am writing a report builder in Symfony2.
I have a config file like this:
bundle:
sections:
Report1:
buckets:
bucket1:
...
calculations:
calculation1:
...
report:
rows:
row1:
...
For several reports, this gets to be loooong.
I've tried breaking this file into smaller files and loading them separately. This didn't work. Here's what I tried:
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('bundle_report.yml');
$loader->load('bundle_report_1.yml'); // Order is important here
$loader->load('bundle_report_2.yml');
$loader->load('bundle_report_3.yml');
$loader->load('services.yml');
}
What's the best way to do this? Is it even possible?
The error I'm getting is (exception is thrown before $loader->load()s happen):
The child node "sections" at path "bundle" must be configured
If I switch the order ( $loader->load()s first, then new Configuration()):
There is no extension able to load the configuration for "bundle"
Configuration looks like this:
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('bundle');
$rootNode
->children()
->arrayNode('sections')->isRequired()
->prototype('array')
...
Here's what I did.
Loaded it all into one 'bundle.yml' config file.
Put that file in app/config
Imported it in app/config.yml imports section
Defined the 'Configuration' class in my bundle (see above). Bundle generator created this.
Then, in my BundleReportExtension class, added these lines
// Parse our configuration. It's included in /app/config/config.yml
// Parser is Configuration class in this package.
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
// Great. Parsed. Now copy to parameters for later use.
$container->setParameter('bundle.default_config', $config['default_config']);
$container->setParameter('bundle.sections', $config['sections']);
Now, I can't get the configuration as an array with:
$container->setParameter('bundle.sections');
In much searching this is the best I could come up with. If you have other suggestions, please share.
You are not supposed to load your config files from the load method.
This is made to
load the base config from Configuration class
compare it to custom config (yml files in app/config/)
and load the bundle services
All your config files must be in app/config/ to be passed as parameters to the load method. As you do it here, they are useless.
That's why you get
The child node "sections" at path "bundle" must be configured
And if you reports are evolving, maybe it's better to put this in a business logic (model/entities) and to plug an admin (eg: sonata admin).
This is the very first time I use Symfony2 by myself and I think I've made a mistake when configuring the FOS User Bundle.
Looks like my User entity does not properly extend the FOS\UserBundle\Entity\User.
Here's my User class (basically the same as mentioned on the doc)
<?php
// src/Acme/UserBundle/Entity/User.php
namespace VillaPrivee\UserBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use FOS\UserBundle\Entity\User as BaseUser;
/**
* #ORM\Entity
* #ORM\Table(name="user")
*/
class User extends BaseUser
{
/**
* #ORM\Id
* #ORM\Column(type="integer")
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
public function __construct()
{
parent::__construct();
// your own logic
}
}
Since I use Netbeans, I'm able to "Ctrl click" and make sure "FOS\UserBundle\Entity\User" exists.
So far, I don't see anything wrong...
But when I try to create a new user using my terminal, I get this error:
Fatal error: Call to undefined method VillaPrivee\UserBundle\Entity\User::setUsername()
in /Applications/MAMP/htdocs/VillaPrivee/vendor/friendsofsymfony/
user-bundle/FOS/UserBundle/Util/UserManipulator.php on line 50
Not sure what other details I should provide you guys with, just let me know if any other file could matter in this case.
Thanks for your help!
Edit :
<?php
namespace VillaPrivee\UserBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class VillaPriveeUserBundle extends Bundle
{
public function getParent()
{
return 'FOSUserBundle';
}
}
config.yml:
fos_user:
db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel'
firewall_name: main
user_class: VillaPrivee\UserBundle\Entity\User
I think you extend wrong class, try with:
use FOS\UserBundle\Model\User as BaseUser;
Edit:
Yep, extending FOS\UserBundle\Entity\User is deprecated, Extend FOS\UserBundle\Model\User directly.
Documentation
Just in case someone gets the same issue as I did, i found out where the problem came from : I'm using a Mac but didn't want to get in trouble using the embedded PHP server. So I decided to use MAMP... Huge mistake!
Everything I tried using my terminal was trying to access default PHP instead of MAMP one...
Basically, I had to remove MAMP and upgrade my Mac PHP so I could use it together with Symfony.
Sorry if I'm not crystal clear, but I don't really understand it all myself...
PS: For those using MAMP, don't be as stupid as I am : your project folder is stored INSIDE your MAMP application folder. So if you trash it, you'll trash all your projects at the same time... Yep, I'm still crying about it!
I have also encountered this issue. This video really helped me.
https://knpuniversity.com/screencast/fosuserbundle-ftw
in AppKernel.php
This was my mistake:
$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 AppBundle\AppBundle(),
new FOS\UserBundle\FOSUserBundle(),
new \Acme\UserBundle\Entity\User()
);
This is the problem new \Acme\UserBundle\Entity\User()
Follow the video and you will see that you need something like this
$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 AppBundle\AppBundle(),
new FOS\UserBundle\FOSUserBundle(),
new \Acme\UserBundle\AcmeUserBundle()
);
Here is the AcmeUserBundle class:
// src/Acme/UserBundle/AcmeUserBundle.php
namespace Acme\UserBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class AcmeUserBundle extends Bundle
{
}
The UserBundle\Entity\User class is just like in the documentation
One last thing that I also saw on the view was the orm: entry in the config.yml Notice the auto_mapping: true
doctrine:
dbal:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
orm:
default_entity_manager: default
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: true
Hops this will help someone else
In Symfony2, everytime I clear my cache via the console:
php app/console cache:clear
The console prints out the contents of my services.yml file! If I manually delete the cache via rm -rf app/cache/* (which I have to do since my console user doesn't have access to the apache user www-data, for some reason, despite being in the same group because the files are created as 640 instead of 660), then the public website also prints it out the FIRST time the page is loaded and the cache is generated.
NOTE: this prints out even if services.yml is NOT loaded in the app/config/config.yml (just by existing, somehow it's being referenced)
We import the services.yml file:
# /app/config/config.yml
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: "#AcmeBundle/Resources/config/services.yml" }
Then set global services in the services.yml file:
# /src/Acme/Bundle/Resources/config/services.yml
# TODO: ALERT! this prints out whenever I clear the cache...
services:
#This is a service so that we can access the view object anywhere
acme.view:
class: Acme\Bundle\Controller\ViewController
arguments: [ #doctrine.orm.entity_manager ]
Question: Any ideas why this file is printing out every time I clear the cache?
This was caused by changing the /Acme/Bundle/Resources/config/services.yml services parameters from PHP to YAML format (I created as PHP originally in my testing).
The reference to the service parameters file is hard coded in the /Acme/Bundle/DependencyInjection/AcmeBundleExtension.php in two places.
Here is the broken code:
class AcmeBundleExtension extends Extension
{
/**
* {#inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new Loader\PhpFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
}
}
Since the services.yml was being loaded as a PHP file, it was just printing out text whenever the cache was recreated. Amazingly, all the services still actually loaded somehow...!
So take note, if you change the config file from PHP to YAML (or vice versa) you have to update:
$loader->load('services.yml');
(which I did)
But also you must update the loader function from Loader\PhpFileLoader to Loader\YamlFileLoader:
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
Of course that seems obvious, but if you are new to Symfony, take note that converting formats of your service config file requires more than just changing your file name.
I am using symfony on Windows and I tried to configure FOSUserBundle as described in the official documentation.
I get this error when try to update the schema:
Class 'FOS\UserBundle\FOSUserBundle' not found in app/AppKernel.php line 20;
searched for the problem and find this solution:
adding this to autoload.php
$loader->registerNamespaces(array(
//all the rest
'FOS' => $vendor_dir . '/bundles',
));
but it returns another error which says
call to undefined method ...\ClassLoader::RegisterNamespace() in ...\autoload.php on line 13
can anybody plz tell me what should i do?:|
and this is my appkernel.php file:
<?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 Sad\Bundle\WarehouseBundle\SadWarehouseBundle(),
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');
}
}
I had the same problem. I found out that the FOSUserBundle was not properly installed. You should delete your /vendor/friendsofsymfony/ directory and then update the bundle using:
php composer.phar update friendsofsymfony/user-bundle
It worked for me. I hope it helps someone else having the same issue.
Alright, there seems to be nothing wrong with your code.
Before we can get on the workarounds, let's try to reinstall your bundle, through the following steps:
Remove that $loader->registerNamespaces(...) thing you added to autoloader.php.
Run php composer.phar self-update to update composer.
Remove the line use FOS\UserBundle\FOSUserBundle(), from AppKernel.php.
Run php composer.phar update to update all your bundles.
Clear your cache, running php app/console cache:clear.
Add the line use FOS\UserBundle\FOSUserBundle(), to AppKernel.php again.
Those should do it. If you still can't use the bundle and you need the workaround (which I wouldn't advice), this is the way to go:
Open app/autoload.php. Right after $loader = require __DIR__ . '/../vendor/autoload.php. add the following:
//Loads FOSUserBundle
$loader->add('FOS', __DIR__.'/../vendor/friendsofsymfony/user-bundle/FOS');
Again, this should fix the issue and yet is not the correct way to do things. Your bundle should be working.
To fix this error in Symfony 3.x.
If composer can not be executed and you can only transfer the files by FTP, it's necessary to update the file:
vendor/composer
and maybe
vendor/symfony (if the version is updated)
The same solution applies to this error
Fatal error: Class 'FOS \ JsRoutingBundle \ FOSJsRoutingBundle' not
found