Various Tips and Tricks¶
Use Find usages of PhpStorm for examples! The source code of the Core is a great way to learn how specific methods of the API are used. In PhpStorm it is extremely helpful to right click on a single method and list all method usages with Find usages. This is especially handy to quickly see usage examples of complex methods like
DELETEstatements are often easier to read and write using the
Connectionobject instead of the
SELECT DISTINCT aFieldis not supported but can be substituted with a
executeQuery()can be used after each other during
development to simplify debugging:
$queryBuilder ->select('uid') ->from('tt_content') ->where( $queryBuilder->expr()->eq('bodytext', $queryBuilder->createNamedParameter('klaus')) ); debug($queryBuilder->getSql()); $result = $queryBuilder->executeQuery();
In contrast to the old API based on
$GLOBALS['TYPO3_DB'], Doctrine DBAL will throw exceptions if something goes wrong when calling
executeQuery(). The exception type is a
\Doctrine\DBAL\Exceptionwhich can be caught and transferred to a better error message if the application has to expect query errors. Note this is not good habit and often indicates an architectural flaw of the application at a different layer.
count()query types using the
->fetchOne()to receive the count value. The
Connectionobject does that automatically and returns the count value result directly.