Reputation: 490
I want to create a symfony app with MicroKernelTrait. I have problem with doctrine and creating query.
I use this example(single file): https://symfony.com/doc/current/configuration/micro_kernel_trait.html
How i should configure db(separate file or not) and which bundles I need?
PS. I will be grateful for the simple example.
Upvotes: 0
Views: 211
Reputation: 4244
All you need is to install DoctrineBundle
, then register and configure it:
$ composer require doctrine/doctrine-bundle
//index.php
//…
class AppKernel extends Kernel
{
//…
public function registerBundles()
{
return array(
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Symfony\Bundle\FrameworkBundle\FrameworkBundle()
);
}
//…
protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader)
{
//…
// in-file config
$c->loadFromExtension('doctrine', array(
'dbal' => array(
'driver' => 'pdo_mysql',
'host' => '127.0.0.1',
'port' => null,
'dbname' => 'symfony',
'user' => 'root',
'password' => 'Pa$$w0rd',
'charset' => 'UTF8'
)
));
// or from-file config
// $loader->load(__DIR__.'/config/doctrine.yml');
}
}
After that, you can access Doctrine by $this->container->get('doctrine');
.
Upvotes: 1