Zum Inhalt springen

Query mit foreach auslesen

Erstellt am 21. September 2020 · 1 Antwort · letzte Antwort am 24. September 2020

Tags: Extbase, Datenbank, TYPO3 8, Frage

sanktusm ·

Hallo,
ich möchte eine Abfrage aus der Datenbank (eine Tabelle) mit foreach auslesen.
Mein Controller sieht so aus:

public function listAction()
    {




        if($this->request->hasArgument('search')) {

        $search = $this->request->getArgument('search');



        $coSmartSearches = $this->coSmartSearchRepository->findAll();

        $explode_res = Array();

        foreach($coSmartSearches as $key => $value) {

          $explode_res[$key] = explode('\n',$value);

        }

die(print_r($explode_res)); //gibt Array ( [0] => Array ( [0] => Covisionmedia\CoSmartsearch\Domain\Model\CoSmartSearch:0 ) ) aus 

        $field = 'SQL_NO_CACHE tt_content.uid, tt_content.tx_mask_searchkeys, tt_content.tx_mask_zubehoer_list, tt_content.header';
        $from  = 'tt_content';
        $where  = 'tt_content.header LIKE '."'" . '%' . $search . '%' ."'" . '';
        $groub_by = '';
        $order_by = 'tt_content.header ASC';
        $limit = '';


        $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($field, $from, $where, $groub_by, $order_by, $limit);

        $this->view->assign('coSmartSearches', $res);

        }

    }

meine Repository so:

<?php
namespace Covisionmedia\CoSmartsearch\Domain\Repository;




/***
 *
 * This file is part of the "covision smart search" Extension for TYPO3 CMS.
 *
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
 *
 *  (c) 2020
 *
 ***/

/**
 * The repository for CoSmartSearches
 */


use \TYPO3\CMS\Extbase\Persistence\Repository;


class CoSmartSearchRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
{

public function findAll() {

$query = $this -> createQuery();

$query->statement('SELECT table_names, table_columns, table_joins FROM tx_cosmartsearch_domain_model_cosmartsearch');

return $query->execute();

}

}
sanktusm ·

So geht es:

public function findAll() {

$query = $this -> createQuery();

$query->statement('SELECT tx_cosmartsearch_domain_model_cosmartsearch.table_names, tx_cosmartsearch_domain_model_cosmartsearch.table_columns, tx_cosmartsearch_domain_model_cosmartsearch.table_joins FROM tx_cosmartsearch_domain_model_cosmartsearch');

return $query->execute(true);

mit execute (true)