CakePHP 3:更改 dateWidget 中的顺序

CakePHP 3: change order in dateWidget

我在 the CakePHP developer's guide 上找到了以下有关在使用 date 表单输入时如何调整字段顺序的提示。它说

To control the order of inputs, and any elements/content between the inputs you can override the dateWidget template.

但是,我无法在任何地方找到有关如何更改顺序并在视图中使用它的提示。能给点提示吗?

您可以在初始化表单助手时配置 DateWidget 模板

// in MyController.initialize()
$this->loadHelper('Form', [
    'dateWidget' => '{{year}}{{month}}{{day}}{{hour}}{{minute}}{{second}}{{meridian}}'
]);

或者您可以使用表单组件

中的templates函数覆盖模板
$this->Form->templates([
    'dateWidget' => '{{year}}{{month}}{{day}}{{hour}}{{minute}}{{second}}{{meridian}}'
]);

@见http://book.cakephp.org/3.0/en/views/helpers/form.html#customizing-the-templates-formhelper-uses

仅供参考...这似乎也可以直接放在视图中:

<?= $this->Form->input('date_of_birth',               
    [ 
    'templates' => [ 
        'dateWidget' => '<div class="clearfix">{{month}}<span class="spacer-date">/</span>{{day}}<span class="spacer-date">/</span>{{year}}</div>',
    ],
    'type' => 'date',
    'label' => 'Date of Birth',
    'empty' => array(
        'month' => '(month)',
        'day'   => '(day)',
        'year'  => '(year)'
    ),
    'minYear' => date('Y') - 70,
    'maxYear' => date('Y') - 18
    ]
) ?>