我想用MicroKernelTrait创建一个symfony应用程序。我对教义和创建查询有问题。
我使用这个例子(单个文件):https://symfony.com/doc/current/configuration/micro_kernel_trait.html
我应该如何配置db(是否单独文件)以及我需要哪些bundle?
PS。我将非常感谢这个简单的例子。
发布于 2017-07-10 16:58:47
您只需安装DoctrineBundle,然后对其进行注册和配置:
$ 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');
}
}在此之后,您可以通过$this->container->get('doctrine');访问Doctrine。
https://stackoverflow.com/questions/45006863
复制相似问题