Last active
December 16, 2015 12:19
-
-
Save bwaidelich/5433673 to your computer and use it in GitHub Desktop.
This snippet shows you how you can use Fluid widgets with DQL queries in TYPO3.Flow today with a little hack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace Your\Package\Domain\Repository; | |
| use TYPO3\Flow\Annotations as Flow; | |
| use TYPO3\Flow\Persistence\Doctrine\Repository; | |
| use TYPO3\Flow\Reflection\ObjectAccess; | |
| /** | |
| * @Flow\Scope("singleton") | |
| */ | |
| class ProductRepository extends Repository { | |
| /** | |
| * @param string $foo | |
| * @return \TYPO3\Flow\Persistence\QueryResultInterface | |
| */ | |
| public function findByFoo($foo) { | |
| $query = $this->createQuery(); | |
| /** @var $queryBuilder \Doctrine\ORM\QueryBuilder **/ | |
| // TODO !hack alarm! replace this once API is available in TYPO3.Flow: | |
| $queryBuilder = ObjectAccess::getProperty($query, 'queryBuilder', TRUE); | |
| $queryBuilder | |
| ->resetDQLParts() | |
| ->select('product') | |
| ->from('Your\Package\Domain\Model\Product', 'product') | |
| ->where('product.active = 1'); | |
| ->andWhere('product.foo = :foo') | |
| ->orderBy('product.title') | |
| ->addOrderBy('product.price', 'DESC') | |
| ->setParameter('foo', $foo) | |
| return $query->execute(); | |
| } | |
| } | |
| ?> |
Author
Is there an update on how to use DQL with Flow? Do we still have to use the ObjectAccess::getProperty() hack or is there some API in the meantime?
Is there an update on how to use DQL with Flow? Do we still have to use the ObjectAccess::getProperty() hack or is there some API in the meantime?
http://stackoverflow.com/questions/27443604/get-table-name-of-an-entity-for-a-query-in-typo3-flow
See the first answer.
Edit:
protected $entityManager;
$dql = 'SELECT COUNT(e) FROM Vendor\Package\Domain\Model\Entity e WHERE e.property = :property';
$query = $this->entityManager->createQuery($dql);
$query->setParameters(array('property' => $property));
$result = $query->execute();
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Julle, just see your comment now ;)
You're right, it should work with the generic base repository, too.
BTW: Instead of using the fluent interface, you can also set raw DQL or use
$queryBuilder->add()