Search code examples
mysqldoctrine-ormflow-framework

typo3 flow: "Result could not be converted to string" - get field content of query result


Good morning,

my repository looks like this:

public function findbyBeitrag($BS) {

    $query = $this->createQuery();
    $query->matching(
        $query->equals('name', $BS)
        );
    return $query->execute();
}

My controller looks like that:

public function findbyBeitragAction() {
     $BS = '1';
     $ergebnis = $this->beitragssatzRepository->findByBeitrag($BS);
     return . $ergebnis . '!';
}

The database looks like that:

     name     beitragssatz
     1        15,00
     2        30,00
     3        40,00

As result of the query I want to get "15,00". What do I have to add to the function in the repository to get as result of my query only the 15,00? I get the error message "Result could not be converted to string".

Thank you very much.


Solution

  • Inject Doctrine's Entity Manger in the repository:

    /** * @Flow\Inject * @var \Doctrine\Common\Persistence\ObjectManager */ 
    protected $entityManager; 
    

    Then with the following :

    $query = $this->entityManager->createQuery("SELECT beitragssatz.beitragssatz FROM \itoop\atc\Domain\Model\Beitragssatz beitragssatz WHERE beitragssatz.name = '1'"); 
    

    I got an output as array. Then with

    $query->getSingleScalarResult();