Created
September 17, 2015 09:47
-
-
Save kaystrobach/c6fe48382dcc81902e7d to your computer and use it in GitHub Desktop.
An ugly viewHelper to get a record from the database ...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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