Symfony2 - DoctrineFixturesBundle - DoctrineCommand not found - symfony

I'm trying to manually add DoctrineFixturesBundle to my symfony project when I do so I get the following error.
C:\wwwnet\symfony>php app/console doctrine:fixtures:load
Fatal error: Class 'Doctrine\Bundle\DoctrineBundle\Command\DoctrineCommand' not found in C:\wwwnet\symfony\vendor\bundles\Doctrine\Bundle\FixturesBundle\Command\LoadDataFixturesDoctrineCommand.php on line 34
I've followed the steps out lined here How to install a Symfony 2.0 Bundle from Zip file
In my AppKernel I have added:
$bundles[] = new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle();
In autoload I have:
'Doctrine\\Bundle' => __DIR__.'/../vendor/bundles',
//'Symfony\\Bundle\\DoctrineFixturesBundle' => __DIR__.'/../vendor/bundles',
//'Doctrine\\Bundle\\DoctrineFixturesBundle' => __DIR__.'/../vendor/bundles',
'Doctrine\\Common\\DataFixtures' => __DIR__.'/../vendor/doctrine-fixtures/lib',
'Doctrine\\Common' => __DIR__.'/../vendor/doctrine-common/lib',
'Doctrine\\DBAL' => __DIR__.'/../vendor/doctrine-dbal/lib',
'Doctrine' => __DIR__.'/../vendor/doctrine/lib',
I have added the bundle to:
C:\wwwnet\symfony\vendor\bundles\Doctrine\Bundle\FixturesBundle
I've seen this question Symfony2 DoctrineFixturesBundle namespace error and it seems to suggest I am probably using the 2.1 bundle with 2.0 symfony
Also, the DoctrineBundle will never be in the Doctrine\Bundle namespace as long as you are on Symfony 2.0.x. Symfony 2.0.x ships with the DoctrineBundle under bundles\Symfony. Your problem is that you are trying to use a too new version of the DoctrineFixturesBundle which expects the DoctrineBundle under Doctrine\Bundle. My first suggestion, tagging the bundle to version=origin/2.0 should solve this. – leek Mar 11 at 20:22
How do I grab the 2.0 bundle for https://github.com/doctrine/DoctrineFixturesBundle? If that is even the problem, I am in the dark on this and have been scratching my head aimlessly for two days now.
Symfony: Symfony_Standard_Vendors_2.0.16
PHP: 5.3.6
Apache: 2.2

In your deps file add
[doctrine-fixtures]
git=http://github.com/doctrine/data-fixtures.git
[DoctrineFixturesBundle]
git=http://github.com/doctrine/DoctrineFixturesBundle.git
target=/bundles/Symfony/Bundle/DoctrineFixturesBundle
version=origin/2.0
so you are defining version in the last line, do a bin/vendor update after that

Related

Install twig/extensions on a Symfony 4 or Symfony 5 new project

I'm preparing to migrate a huge website from Symfony 3.4 to Symfony 4.4.
To do this, I'm starting from a new fresh installation of Symfony 4.4, and as the intial project requires the use of Twig Extensions I try to install it on this new Symfony 4.4 project.
But composer indicates Your requirements could not be resolved to an installable set of packages.
The error message is obvious, but I don't understand why this situation happens on a fresh symfony 4.4 project.
What I tried :
I create a new Symfony symfony new --full --version=lts testproject that installed Symfony 4.4 and right after composer require twig/extensions => Your requirements could not be resolved to an installable set of packages.
I create a new Symfony symfony new --full testproject that installed Symfony 5.0 and right after composer require twig/extensions => Your requirements could not be resolved to an installable set of packages.
I tried with Symfony flex but same problem => Your requirements could not be resolved to an installable set of packages.
I retried after clearing the composer cache but no change.
This worked :
- I create a new Symfony symfony new --full --version=3.4 testproject that installed Symfony 3.4 and right after composer require twig/extensions => OK
I understand that dependencies conflits occur for Symfony 4.4 and more, but according to Symfony doc How to Write a custom Twig Extension no further actions are required and it should work.
What I'm missing ? Does someone faced the same problem ? Thanks
if you're using Flex, you should install twig first:
composer req twig
then, do:
composer require twig/extensions
I hope that help.
Finally it seems that running composer require twig/extensions is no more required to create custom Twig Extensions in Symfony 4.
By default a new Symfony built with website skeleton owes a use Twig\Extension\AbstractExtension; as per required to create a twig extension like below one :
namespace App\Twig;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
class AppExtension extends AbstractExtension
{
public function getFilters()
{
return [
new TwigFilter('price', [$this, 'formatPrice']),
];
}
public function formatPrice($number, $decimals = 0, $decPoint = '.', $thousandsSep = ',')
{
$price = number_format($number, $decimals, $decPoint, $thousandsSep);
$price = '$'.$price;
return $price;
}
}

Symfony 2: LiipDoctrineCacheBundle not found in AppKernel

I've installed this bundle LiipDoctrineCacheBundle in vendor\bundles\ folder of my website.
Then, as usual, I added in autoload.php a new entry in the array namespace:
'Liip' => __DIR__.'/../vendor/bundles',
And I registered this new bundle in the bundles' array of AppKernel.php:
new Liip\DoctrineCacheBundle\LiipDoctrineCacheBundle(),
But weirdly I get this error message:
Fatal error: Class 'liip\DoctrineCacheBundle\LiipDoctrineCacheBundle' not found in C:\workspace\LHN\app\AppKernel.php on line 26
It's like if Symfony cannot retrieve the bundle in the nameSpace...
So I've tried by changing the case of the bundle key: 'Liip'==> 'liip'
And I've also tried with the fully path location:
__DIR__.'/../vendor/bundles' ==> C:\workspace\mySite\vendor\bundles
Any idea?
Thks
Symfony: 2.0.9
Liip bundle: master
You are probably using the wrong name for the bundle class.
i think it should be
new Liip\LiipDoctrineCacheBundle\LiipDoctrineCacheBundle()
or
new liip\LiipDoctrineCacheBundle\LiipDoctrineCacheBundle()
not sure if the first "L" is capital or not in your vendor/bundles/ source
Thanks to Laurynas's comment I understood my problem: the source bundle path was wrong
vendor\bundles\liip\LiipDoctrineCacheBundle
instead of
vendor\bundles\Liip\DoctrineCacheBundle
The origin of this issue is that I made a mistake in the deps file (where the git location, the version and the target directory are defined) by setting the target property to /bundles/liip/LiipDoctrineCacheBundle instead of to /bundles/Liip/DoctrineCacheBundle.
My bad... ;-)
Correct dep block:
[LiipDoctrineCacheBundle]
git=https://github.com/liip/LiipDoctrineCacheBundle.git
target=/bundles/Liip/DoctrineCacheBundle
version=master

Undefined method registerNamespaces() symfony2

I'm following this FOSTwitterBundle documentation:
https://github.com/FriendsOfSymfony/FOSTwitterBundle
I did it all step by step, but when I access my site, i get this error:
Fatal error: Call to undefined method Composer\Autoload\ClassLoader::registerNamespaces() in C:\xampp\htdocs\Symfony\app\autoload.php on line 16
My autoload.php is like this:
<?php
use Doctrine\Common\Annotations\AnnotationRegistry;
$loader = require __DIR__.'/../vendor/autoload.php';
// 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'));
$loader->registerNamespaces(array(
// ...
'FOS' => __DIR__.'/../vendor/bundles',
// ...
));
return $loader;
What should I do?
for symfony 2.*
replace this
$loader->add('FOS' => __DIR__.'/../vendor/bundles');
with
$loader->add('FOS', __DIR__.'/../vendor/bundles');
The basic problem is that the installation directions are for Symfony 2.0. You are using S2.1. I have not poked around in the twitter bundle. Hard to say if it will even run under 2.1. Installing it via git submodule instead of using composer seems strange.
Try starting over and adding: "friendsofsymfony/twitter-bundle": "dev-master" to your composer.json and doing an install. This should bring down the packages and take care of autoloading for you.
Otherwise, replace:
$loader->registerNamespaces(array('FOS' => __DIR__.'/../vendor/bundles'));
with
$loader->add('FOS' => __DIR__.'/../vendor/bundles');
S2.1 uses a different class loader than S2.0 with a different interface. It will at least get you past the error message.
But again, try the composer route first and then maybe submit a patch to the project to update the readme file.
OAuth?
I used https://github.com/hwi/HWIOAuthBundle no long time ago.
How to integrate with FOSUB: https://github.com/hwi/HWIOAuthBundle/issues/81

Symfony2 Solarium Class 'Solarium_Plugin_Abstract' not found

I am using https://github.com/nelmio/NelmioSolariumBundle and I am trying to conect with solarium y my symfony2 application.
I have installed solarium with the composer.json but then I get
Class 'Solarium_Plugin_Abstract' not found in .../vendor/bundles/Nelmio/SolariumBundle/Logger.php on line 12
I don't understand why in the Logger there is:
use Solarium_Plugin_Abstract
But in the folders I find:
myproject/vendor/solarium/library/Solarium/Plugin/Abstract.php
I have declared in my autoload.php
'Solarium' => DIR.'/../vendor/solarium/library',
Should't be: use Solarium/Pluguin/Abstract ?
What I am doing wrong?

Installing LiipImagineBundle for Symfony 2.1 using Composer

LiipImagineBundle doesn't seem to have instructions for installing itself using composer (github page) so I added
"liip/imagine-bundle": "*",
to my composer.json and updated. Everything went fine until I tried to register the bundle in appKernel.php with the line
new Liip\ImagineBundle\LiipImagineBundle(),
Php gives the error
Fatal error: Class 'Liip\ImagineBundle\LiipImagineBundle' not found in C:\xampp\htdocs\xxxx\Symfony\app\AppKernel.php on line 24
As far as I can see LiipImagineBundle is in the right place in the vendors folder. Anyone have any idea where I'm going wrong? Thanks in advance.
*Edit I should add I'm using symfony 2.1
I had to change the line in composer to this:
"liip/imagine-bundle": "*#dev"
notice the #dev at the end. This tell composer that I am willing to accept "dev" stability
I contacted the developer of the bundle and found that there is a vendor/composer/autoload_namespaces.php where you can manually add entries and the bundle wasn't there.
This guide was helpful: Composer Namespaces in 5 Minutes
I'm using Symfony 2.1.4-DEV and including "liip/imagine-bundle": "*" on the composer.json and updating it works
Did you registered Namespace in autoload.php and registered Bundle in AppKernel.php? If not the class will be not avialable to use until registration there.
As the documentation says:
<?php
// app/autoload.php
$loader->registerNamespaces(array(
// ...
'Imagine' => __DIR__.'/../vendor/imagine/lib',
'Liip' => __DIR__.'/../vendor/bundles',
));
And
<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new Liip\ImagineBundle\LiipImagineBundle(),
);
}
Update
Run composer update it will regenerate your bootstrap files. tell me if any luck with this.

Resources