【问题标题】:Cakephp 4 Form Helper: Create Individual dropdown for day, month and yearCakephp 4 表单助手:为日、月和年创建单独的下拉列表
【发布时间】:2020-07-03 08:15:01
【问题描述】:

所以,在 CakePHP 3 中,要得到这样的东西:

我会这样做:

 <?= $this->Form->date('dob', [
   'templates' => ['inputContainer' => '{{content}}'], 'label' => false, 'class' => 'form-control', 'minYear' => 1940, 'maxYear' => date('Y') - 5,
   'empty' => [
      'year' => "Year", // The year select control has no option for empty value
      'month' => 'Month', // The month select control does, though
      'day' => 'Day', // The month select control does, though
   ],
 ]) ?>

但是,如果我尝试在 Cakephp 4 上做同样的事情,我会得到这个

我已经浏览了这里的文档:https://book.cakephp.org/3/en/views/helpers/form.html#creating-date-time-related-controlshttps://book.cakephp.org/4/en/views/helpers/form.html

请问我怎样才能在 Cakephp 4 上实现相同的 Cakephp 3 输出

【问题讨论】:

    标签: php cakephp cakephp-4.x


    【解决方案1】:

    你试过了吗

    'type' => 'select'
    

    如记录? 否则,自定义模板可能会有所帮助。

    或者,下拉默认部分被移动到Shim插件 见https://github.com/dereuromark/cakephp-shim/blob/master/docs/View/Form.md 这应该为您提供创建此类表单元素的 3.x 方式。

    【讨论】:

    • 是的,我确实尝试过 'type'=>'select' 并且我在我的数据库中使用了相同的日期列类型
    • 您可以在这里创建自己的模板。我相信您会查看 this 并了解如何做到这一点。
    猜你喜欢
    • 2012-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多