Attention
TYPO3 v8 has reached its end-of-life March 31st, 2020 and is not maintained by the community anymore. Looking for a stable version? Use the version switch on the top left.
There is no further ELTS support. It is recommended that you upgrade your project and use a supported version of TYPO3.
Various tips and tricks¶
Use
Find usages
ofPhpStorm
for examples! The source code of the core is a great way to learn how specific methods of the API are used. InPhpStorm
it is extremely helpful to right click on a single method and list all method usages withFind usages
. This is especially handy to quickly see usage examples of complex methods likejoin()
from theQueryBuilder
.INSERT
,UPDATE
andDELETE
statements are often easier to read and write using theConnection
object instead of theQueryBuilder
.SELECT DISTINCT aField
is not supported but can be substituted with a->groupBy('aField')
.getSQL()
andexecute()
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()); $statement = $queryBuilder->execute();
In contrast to the old API based on
$GLOBALS['TYPO3_DB']
,doctrine-dbal
will throw exceptions if something goes wrong when callingexecute()
. The exception type is a\Doctrine\DBAL\DBALException
which 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 theQueryBuilder
typically call->fetchColumn(0)
to receive the count value. Thecount()
method ofConnection
object does that automatically and returns the count value result directly.