Symfony 6.1 Doctrine QueryBuilder "class xxx is not defined" - symfony

I'm trying to move a Symfony 3.4 app to 6.1. I've done this by creating a brand new, clean 6.1 app and am copying things over.
I'm stuck with some Doctrine queryBuilders, eg.
$this->query = $em->createQueryBuilder()
->select('c')
->from('Customer' , 'c');
This code is in a Controller, not a Repository. This gives the error
[Semantical Error] line 0, col 14 near 'Customer c ORDER': Error: Class 'Customer' is not defined.
In the 3.4 version, 'Customer' was prefixed by the bundle name. In the 6.1 version, there is no bundle. I understand that the bundle name in 3.4 showed Doctrine which Entity 'Customer' referred to, how do I do the same in 6.1 with no bundle?

Prefixing with App\Entity\ works! Eg:
$this->query = $em->createQueryBuilder()
->select('c')
->from('App\Entity\Customer' , 'c');

Related

Support for mapping keys in multi-line blocks is deprecated since Symfony 4.3 and will throw a ParseException in 5.0

I have a problem. After updating to Symfony 4.4 I got the following deprecation warning
Support for mapping keys in multi-line blocks is deprecated since Symfony 4.3 and will throw a ParseException in 5.0.
2x in AccountControllerTest::testSettings from App\Tests\Controller
1x in AccountControllerTest::testPageUser from App\Tests\Controller
I have absolutely no clue what this means.
testSettings from App\Tests\Controller:
public function testSettings() {
$crawler = self::$userClient->request('GET', '/nl/account/settings.html');
$this->assertSuccesfulResponse(self::$userClient->getResponse());
$crawler = $this->form(self::$userClient, $crawler, 'submit', array(), '/\/nl\/account/');
}
Thanks in advance!
This mean that you potentially have a multi line key in your somewhere in a Yaml file and it's not supported by symfony and in symfony 5.0 it will throw an exception not a warning !
Something like that:
this
is
multi
key: test

Entity property not found error in symfony

In prod mode of symfony, I get the below error.
"message": "[Semantical Error] line 0, col 134 near 'stock = :sto':
Error: Class AppBundle\\Entity\\CartItem has no field or association named stock",
Actually before few days I added a stock property in my CartItem Entity.
This is working in dev environment but giving error in prod environment.

Symfony 1.2 to 2.3 migration

I've got a pretty big Symfony 1.2 project to migrate.
First, I modified my .htaccess so I can have some pages handled by Symfony 2.
What I'd like to do, to make the migration smoother, is to be able to render some SF2 action/templates/methods/... inside SF1.
I added the autoloader to the SF1 app, so I can access to twig rendering methods and other stuff.
But how can I call a SF2 action ?
For example, if I want to migrate only the footer first, I would also need some php methods, not only rendering. That was previously in SF1 component, where should it be now ?
If you've got any suggestion about the way of migrating, don't hesitate !
EDIT 1 :
Apparently, the only way to do something like that is to render a full twig template, and/or in this template call some other partial twig templates with render(url, params).
Here is my SF1 code to be able to render twig templates :
public static function getTwig()
{
require_once __DIR__.'SF2_PATH/vendor/twig/extensions/lib/Twig/Extensions/Autoloader.php';
Twig_Autoloader::register();
$loader = new Twig_Loader_Filesystem( __DIR__.'SF2_PATH/sf2/src/VENDOR/BUNDLE/');
$twig = new Twig_Environment($loader, array(
'cache' => __DIR__.'SF2_PATH/sf2/app/cache/dev/twig',
));
return $twig;
}
And so :
$twig->loadTemplate('header.html.twig');
EDIT 2 :
That doesn't seem to work, if in a twig template I try to render an other one with {{render(controller('BUNDLE:CONTROLER:ACTION', {})) }} for example Twig_Error : The function "controller" does not exist. And if I try to render the url Unknown tag name "render".
I guess Symfony 2 twig functionalities are not loaded, how can I do that ?
EDIT 3 :
Ok, now I can do it, but I've got the following message...
Twig_Error_Runtime An exception has been thrown during the rendering
of a template ("Rendering a fragment can only be done when handling a
master Request.") in ...
EDIT : I solved it !
Here is my full bootstrap method to render a Twig template and be able to use some Symfony 2 functionalities, in Symfony 1.
$loader = require_once __DIR__.'/../../../sf2/app/bootstrap.php.cache';
Debug::enable();
require_once __DIR__.'/../../../sf2/app/AppKernel.php';
$kernel = new AppKernel('dev', true);
$kernel->loadClassCache();
Request::enableHttpMethodParameterOverride();
$request = Request::createFromGlobals();
$kernel->boot();
$kernel->getContainer()->enterScope('request');
$kernel->getContainer()->set('request', new \Symfony\Component\HttpFoundation\Request(), 'request');
$this->container = $kernel->getContainer()->get('twig');

Symfony 2.1.7 and doctrine migrations bundle error

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.

How to install or integrate bundles in Symfony2

i have downloaded a sonata admin bundle, and have placed in /var/www/Symfony/vendor/symfony/src/Symfony/Bundle, and have made an entry in AppKernel.php as $bundles = array( ... new Symfony\Bundle\SonataAdminBundle\SonataAdminBundle(),), but throwing an error as
Fatal error: Class
'Symfony\Bundle\SonataAdminBundle\SonataAdminBundle' not found in
/var/www/Symfony/app/AppKernel.php on line 21 Call Stack: 0.0001
326332 1. {main}() /var/www/Symfony/web/app_dev.php:0 0.0122 1121592
2. Symfony\Component\HttpKernel\Kernel->handle()
please help me as i am very new to symfony 2. As a whole please give a link or detail like how to install/configure any bundle that is downloaded.
Thanks
Ravi.M
You need to move the bundle to
/var/www/Symfony/vendor/bundles
Then in AppKernel.php add
new Sonata\AdminBundle\SonataAdminBundle(),
in your $bundles array.
In autoload.php add
'Sonata' => __DIR__.'/../vendor/bundles',
to the $loader->registerNamespaces array
First off, SonataAdminBundle lives in Sonata namespace, not Symfony. So you'll have to rewrite the instantiation in app/AppKernel.php to:
new Sonata\AdminBundle\SonataAdminBundle()
You also have to register namespace in app/autoload.php:
$loader->registerNamespaces(array(
...
'Sonata' => __DIR__.'/path/to/parent/of/Sonata/folder'
...
));

Resources