简体   繁体   中英

Individual Database Queries TYPO3 Fluid extension

Im playin around with TYPO3 und fluid to get more familiar with it. I need to do a individual Database Query, and save the output as array. On the official TYPO3 docs page its very straight forward how to do a individual Database Query in my Controller.

/**
 * Returns all objects of this repository.
 *
 * @return QueryResultInterface|array
 * @api
 */
public function findAll()
{
    return $this->createQuery()->execute();
}

As a try i put this public function above in my extension controller, but how can I output the data in the frontend with a for each loop?

I want to output the data in the usermanager extension.

Edit: Using TYPO3 v. 9

You have to assign it to a variable of your Fluid View:

$this->view->assign('varName', $data);

Then you can iterate through "varName" via the Fluid For-ViewHelper: https://docs.typo3.org/other/typo3/view-helper-reference/9.5/en-us/typo3fluid/fluid/latest/For.html

Edit: The code above has to be inside an Repository. The Repository is the "bridge" between the Controller and your Database. To call it you just need to inject the Repository in your Controller ( https://wiki.typo3.org/Dependency_Injection ) and call the findAll function:

public function customAction(): void
{
    $this->view->assign(
        'objects',
        $this->repositoryVarName->findAll()
    );
}

This might help you: https://docs.typo3.org/m/typo3/book-extbasefluid/master/en-us/4-FirstExtension/3-create-the-domain-model.html
https://docs.typo3.org/m/typo3/book-extbasefluid/master/en-us/6-Persistence/2a-creating-the-repositories.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM