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
Related
I use this documentation for install algolia:
https://www.algolia.com/doc/api-client/symfony/setup/
this configuration is already done:
composer require algolia/algolia-search-bundle
And
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Algolia\AlgoliaSearchBundle\AlgoliaAlgoliaSearchBundle(),
);
configuration.yml:
algolia:
application_id: YOUR_APP_ID
api_key: YOUR_API_KEY
but I don't understand , I need a example for implementation in my project.
Please your help
1-) you should install algolia-search-bundle with Composer;
composer require algolia/algolia-search-bundle
2-) add line this -> Algolia\AlgoliaSearchBundle\AlgoliaAlgoliaSearchBundle() at app/AppKernel.php file into $bundles array.
3-)you should add your api keys at app/config/config.yml file;
algolia:
application_id: YOUR_APP_ID
api_key: YOUR_API_KEY
That's enough.
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
I am trying to write a command line app using the Symfony2 Console and ClassLoader Components.
This is a screenshot of my code hierarchy and the script being called
Here is the CLI script:
#!/usr/bin/env php
<?php
require_once(dirname(__FILE__) . '/code/ClassLoader/UniversalClassLoader.php');
use Symfony\Component\ClassLoader\UniversalClassLoader;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use BlueHeadStudios\Command\Deployer;
$loader = new UniversalClassLoader();
$loader->register();
$input = new ArgvInput();
$debug = $input->hasParameterOption(array('--debug', ''));
$console = new Application();
$console->add(new Deployer());
$console->run();
I get this when running the script
dev#server:~/sites/pd/deployer$ php deployer.php
PHP Fatal error: Class 'Symfony\Component\Console\Input\ArgvInput' not found in /home/dev/sites/pd/deployer/deployer.php on line 13
I know it must be a simple registerNamespace call or something similar, but I've tried multiple registrations but cannot get it to work.
Any help is greatly appreciated.
I would recommend you to use composer, which will generate autoload.php for you to include at the top of the file:
#!/usr/bin/env php
<?php
require_once './vendor/autoload.php';
use Symfony\Component\ClassLoader\UniversalClassLoader;
$loader = new UniversalClassLoader();
$loader->registerNamespace('BlueHeadStudios', __DIR__.'/src/');
$loader->register();
// write your code below
You should run the application with app/console check the example here
I am following this tutorial: http://tutorial.symblog.co.uk/docs/extending-the-model-blog-comments.html#doctrine-2-migrations
1) Installing Doctrine migrations bundle
1.1) - adding
"doctrine/migrations": "dev-master",
"doctrine/doctrine-migrations-bundle": "dev-master"
to composer.json
1.2) running
php composer.phar update
2) adding
new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle(),
in AppKernel.php
3) Running
php app/console doctrine:migrations:diff
this should run the command and find the differences between the current entities and the database, yes?
But I get an error instead:
Fatal error: Class 'Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle' not found in D:\xampp\htdocs\symblog.dev\app\AppKernel.php on line 23
This is exactly the line of (2.)
Can you help me out? Any advice is welcome!
I think the bundle was renamed in the meanwhile. Try: (updated question):
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
//...
new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle(),
);
}
See DoctrineMigrationsBundle documentation and DoctrineMigrationsBundle class.
I need to use PHPExcel with a Symfony2 project. Anyone know how to set up the project correctly to use the library? Should i put it in the vendor directory? What should be changed in the configuration files etc?
Actually, to do it right you need to follow next steps:
Edit your deps file and add dependency from the PHPExcel
[PHPExcel]
git=http://github.com/PHPOffice/PHPExcel.git
target=/phpexcel
version=origin/master
Run php bin/vendors install in order to install all missing dependencies (PHPExcel in our case)
Update prefixes section in app/autoload.php:
$loader->registerPrefixes(array(
// ...
'PHPExcel' => __DIR__.'/../vendor/phpexcel/Classes',
));
Done. Now, you can use it in your bundle's controller (code based on PHPExcel example from Tests/01simple-download-xls.php):
<?php
namespace Demo\MyBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use PHPExcel;
use PHPExcel_IOFactory;
class DemoController extends Controller
{
public function demoAction()
{
$response = new Response();
// Create new PHPExcel object
$objPHPExcel = new PHPExcel();
// Set document properties
$objPHPExcel->getProperties()->setCreator("Me")
->setLastModifiedBy("Someone")
->setTitle("My first demo")
->setSubject("Demo Document");
// Add some data
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A1', 'Hello')
->setCellValue('B2', 'world!')
->setCellValue('C1', 'Hello')
->setCellValue('D2', 'world!');
// Set active sheet index to the first sheet
$objPHPExcel->setActiveSheetIndex(0);
// Redirect output to a client’s web browser (Excel5)
$response->headers->set('Content-Type', 'application/vnd.ms-excel');
$response->headers->set('Content-Disposition', 'attachment;filename="demo.xls"');
$response->headers->set('Cache-Control', 'max-age=0');
$response->prepare();
$response->sendHeaders();
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
exit();
}
}
Copy the library to your vendors directory.
Configure autoloader in your bootstrap file:
$loader->registerPrefixes(array(
// Swift, Twig etc.
'PHPExcel' => __DIR__ . '/../vendor/phpexcel/lib/PHPExcel'
));
That's all.
actually the best solution is to use https://github.com/liuggio/ExcelBundle.
I tried to use #Crozin's solution but I was still getting an error about IOFactory::createWriter.
Hope this helps,
Simone
As of Symfony 2.3, you can now do this:
...
"require": {
...
"phpoffice/phpexcel": "dev-master"
...
},
...
Then just run composer update and dependencies will resolve automatically.
Or you can do composer require phpoffice/phpexcel:dev-master if you don't want to mess with the composer.json file.
If you are using composer to manage your project, you can just change the composer.json file:
"autoload": {
"psr-4": {
"": "src/",
"": "vendor/phpoffice/phpexcel/Classes/"
},
"classmap": [
"app/AppKernel.php",
"app/AppCache.php"
]
},
Then add
use PHPExcel;
use PHPExcel_IOFactory;
to your controller file, and you can use the PHPExcel like this:
$objPHPExcel = new PHPExcel();
Hope it helps.
With composer (since Symfony2.1) it's really easy, you only have to modify the composer.json.
You don't need to register the namespace anymore!
Only two things, to notice:
refer to github tags, I only found a soltion with the package type
when changing something in the composer.json related to the class autoloading stuff, you have to remove the whole directory in the vendor dir
Here is the related link: use PHPExcel with composer and Symfony2.2