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

308 Views Asked by At

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.

1

There are 1 best solutions below

0
On BEST ANSWER

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();