Skip to content

Instantly share code, notes, and snippets.

@kaystrobach
Created September 17, 2015 09:47
Show Gist options
  • Save kaystrobach/c6fe48382dcc81902e7d to your computer and use it in GitHub Desktop.
Save kaystrobach/c6fe48382dcc81902e7d to your computer and use it in GitHub Desktop.
An ugly viewHelper to get a record from the database ...
<?php
namespace Vendor\Extension\ViewHelpers;
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
class GetRecordAsViewHelper extends AbstractViewHelper {
/**
* @param string $table
* @param integer $uid
* @param string $as
* @return string
*/
public function render($table, $uid, $as) {
try {
$record = $this->getDb()->exec_SELECTgetSingleRow(
'*',
$table,
'uid=' . (int)$uid
);
$this->templateVariableContainer->add($as, $record);
$buffer = $this->renderChildren();
$this->templateVariableContainer->remove($as);
return $buffer;
} catch(\Exception $e) {
return $e->getMessage();
}
}
/**
* @return \TYPO3\CMS\Core\Database\DatabaseConnection
*/
protected function getDb() {
return $GLOBALS['TYPO3_DB'];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment