[TYPO3-mvc] Date examples, can't find any.
Nathan Lenz
typo3 at k9tfk.com
Tue Jan 12 19:44:26 CET 2010
We need a viewHelper repository. :)
Here is a simple viewHelper that allows the Form_TextboxViewHelper to
work with a DateTime method.
<myext:datetextbox property="published" format="d-m-Y"></myext:datetextbox>
class Tx_Myext_ViewHelpers_DatetextboxViewHelper extends
Tx_Fluid_ViewHelpers_Form_TextboxViewHelper {
/**
* Initialize the arguments.
*
* @return void
*/
public function initializeArguments() {
parent::initializeArguments();
$this->registerTagAttribute('format', 'string', 'The format to render
the date in.');
}
/**
* Renders the textbox.
*
* @return string
* @api
*/
public function render() {
$name = $this->getName();
$this->registerFieldNameForFormTokenGeneration($name);
$this->tag->addAttribute('type', 'text');
$this->tag->addAttribute('name', $name);
/** @var DateTime */
$value = $this->getValue();
$stringValue = $value->format($this->getFormat());
$this->tag->addAttribute('value', $stringValue);
$this->setErrorClassAttribute();
return $this->tag->render();
}
/**
* Get the format that was passed into the tag
* @return string Date format compatible with date()
*/
protected function getFormat() {
return $this->arguments['format'];
}
}
More information about the TYPO3-project-typo3v4mvc
mailing list