TYPO3 Extbase:具有datetime属性的持久域模型 [英] TYPO3 Extbase: persisting domain model with datetime property

查看:83
本文介绍了TYPO3 Extbase:具有datetime属性的持久域模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的被困在这里(也许疾病没有帮助...)。

I am really stuck here (maybe the sickness is not helping...).

设置:
-typo3 6.2带有extbase和流畅的
-检查了大约20个博客条目,官方文档以及一些代码片段,我发现
-开发TYPO3的资深人士,但是对于extbase / fluid来说还是比较新的

Setting: - typo3 6.2 with according extbase and fluid - checked about 20 blog entries, the official docu, and a few code snippets I found - Senior on developing TYPO3, but relatively new to extbase/fluid

目标:
与你们许多人一样,我尝试在前端实现一个表单以创建一个新对象。该对象包含一些日期时间属性。

Goal: As many of you, I try to realize a form in the frontend to create a new object. This object contains some datetime properties.

症状:
-我可以在后端创建一个对象并正确地将其输出创建列表并享受其中的乐趣,到目前为止没有问题。
-填写表单时,我得到所有已知的FlashErrorMessage尝试调用时发生错误
-样式化给出错误的表单字段后(使用了f3-form-error css类)我可以将datetime属性的输入字段确定为坏人。

Symptoms: - I can create an object in the backend and correctly output it with fluid creating lists and having some fun with it, no problem so far. - When filling out the form I get the all known FlashErrorMessage "An error occurred while trying to call" - After styling the form fields that give an error (used the f3-form-error css-class) I could determine the input fields of the datetime properties as the bad guys.

tca摘录:

'startdate' => array(
    'label' => 'LLL:EXT:ngibmembers/Resources/Private/Language/locallang_db.xlf:paymentperiod.startdate',
    'config' => array(
        'type' => 'input',
        'size' => 30,
        'eval' => 'date',
    ),
),
'stopdate' => array(
    'label' => 'LLL:EXT:ngibmembers/Resources/Private/Language/locallang_db.xlf:paymentperiod.stopdate',
    'config' => array(
        'type' => 'input',
        'size' => 30,
        'eval' => 'date',
    ),
),

然后在这里是域模型部分:

then here the domain model part:

/**
 * startdate
 *
 * @var \DateTime
 * @validate DateTime
 */
protected $startdate;

/**
 * stopdate
 *
 * @var \DateTime
 * @validate DateTime
 */
protected $stopdate;

/**
 * Get startdate
 *
 * @return \DateTime
 */
 public function getStartdate(){
     return $this->startdate;
 }

 /**
  * Set startdate
  *
  * @param \DateTime $startdate
  * @return Paymentperiod
  */
  public function setStartdate($startdate){
      $this->startdate = $startdate;
      return $this;
  }

/**
 * Get stopdate
 *
 * @return \DateTime
 */
 public function getStopdate(){
     return $this->stopdate;
 }

/**
 * Set stopdate
 *
 * @param \DateTime $stopdate
 * @return Paymentperiod
 */
 public function setStopdate($stopdate){
     $this->stopdate = $stopdate;
     return $this;
 }

动作

/**
 * convert date properties
 *
 * @return void
 */
public function initializeAction(){
$dateFormat = 'dd.mm.yyyy';
if (isset($this->arguments['paymentperiod'])) {
    $this->arguments['paymentperiod']
        ->getPropertyMappingConfiguration()
        ->forProperty('startdate')
        ->setTypeConverterOption(
            'TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter',
            \TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter::CONFIGURATION_DATE_FORMAT,
            $dateFormat);
}
if (isset($this->arguments['paymentperiod'])) {
    $this->arguments['paymentperiod']
        ->getPropertyMappingConfiguration()
        ->forProperty('stopdate')
        ->setTypeConverterOption(
            'TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter',
            \TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter::CONFIGURATION_DATE_FORMAT,
            $dateFormat);
}
}

/**
 * action new
 *
 * @param \NGiB\Ngibmembers\Domain\Model\Paymentperiod $paymentperiod
 * @ignorevalidation $paymentperiod
 * @return void
 */
public function newAction(\NGiB\Ngibmembers\Domain\Model\Paymentperiod $paymentperiod = NULL) {
    $this->view->assign('paymentperiod',$paymentperiod);
    $this->view->assign('settings',$this->settings);
}

/**
 * action create
 *
 * @param \NGiB\Ngibmembers\Domain\Model\Paymentperiod $paymentperiod
 * @return void
 */
public function createAction(Paymentperiod $paymentperiod) {
    $this->paymentRepository->add($paymentperiod);
    $this->redirect('new');
}

,然后是流体模板中的摘要:

and then the snippets from the fluid template:

<f:form action="create" object="{paymentperiod}" class="form-horizontal" name="paymentperiod">

<f:form.textfield
    id="paymentperiod_field_startdate"
    property="startdate"
    class="form-control" />

那么,我的问题在哪里???

so, where is my problem????

非常感谢所有帮助的人。

Many thanks for everyone who helps.

最诚挚的问候

推荐答案

好,发现了问题:

所以我选择的引导日期选择器在dateformat中需要'dd.mm.yyyy'来提供正确的中欧格式日期。

so the bootstrap datepicker I chose needs 'dd.mm.yyyy' in the dateformat to give a correct central european formatted date.

经过更多的调试和阅读之后,我终于发现,PHP DateTime类使用'dmY'来解析相同的格式。

After some more debugging and reading, I finally found out, that the PHP DateTime class uses 'd.m.Y' to resolve the same format.

在控制器的initializeAction中更改dateFormat解决了验证问题。

changing the dateFormat in the initializeAction of the controller solved the validation problem.

我肯定需要在那里找到一个更好的datepicker库:S

I definitely need to get a better datepicker library there :S

这篇关于TYPO3 Extbase:具有datetime属性的持久域模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆