makinacorpus/query-builder-bundle
最新稳定版本:1.0.0
Composer 安装命令:
composer require makinacorpus/query-builder-bundle
包简介
Symfony integration for makinacorpus/query-builder
README 文档
README
Integrates makinacorpus/query-builder into Symfony.
Setup
First install:
composer require makinacorpus/query-builder-bundle
Then add the bundle to config/bundles.php if symfony/flex did not:
return [ // ... your other bundles. MakinaCorpus\QueryBuilderBundle\QueryBuilderBundle::class => ['all' => true], ];
And you're done.
Services
Each Doctrine connection will have both MakinaCorpus\QueryBuilder\QueryBuilder
and MakinaCorpus\QueryBuilder\DatabaseSession associated service in container.
They are identifier by the query_builder.session.CONNECTION_NAME service
identifier. You can manually inject by using the service name, or use autowiring.
You can target a Doctrine connection by injecting a QueryBuilder or
DatabaseSession typed service by setting the parameter name to the Doctrine
connection name, for example:
<?php declare (strict_types=1); namespace App\Controller; use MakinaCorpus\QueryBuilder\DatabaseSession; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; class TestingController extends AbstractController { #[Route('/testing/query-builder', name: 'testing_query_builder')] public function testQueryBuilder( DatabaseSession $someConnectionName, ): Response { } }
Will have the database session bridged over the some_connection_name
configued Doctrine connection.
Usage
Simply inject the service wherever you need it, a controller action for example:
<?php declare (strict_types=1); namespace App\Controller; use MakinaCorpus\QueryBuilder\DatabaseSession; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; class TestingController extends AbstractController { #[Route('/testing/query-builder', name: 'testing_query_builder')] public function testQueryBuilder( DatabaseSession $session, ): Response { $result = $session ->select('some_table') ->executeQuery() ; $data = []; foreach ($result->iterateAssociative() as $row) { $data[] = $row; } return $this->json($data); } }
Basic, simple.
统计信息
- 总下载量: 17
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-11-16