【问题标题】:How can I set a default date format for all backend fields in OctoberCms?如何为 OctoberCms 中的所有后端字段设置默认日期格式?
【发布时间】:2019-08-20 08:27:18
【问题描述】:

默认情况下,当我在 OctoberCMS 中创建日期字段时,它的格式为 m/d/Y,但我想改用 d/m/Y。

幸运的是,OctoberCMS 允许日期小部件在显示之前使用“格式”属性格式化日期,因此这部分解决了问题。

此“格式”参数并非在所有小部件中都可用,例如,我想创建一个没有它的“列表过滤器”,因此我无法更改日期格式。 (https://octobercms.com/docs/backend/lists#filter-daterange)

有没有办法可以设置所有元素使用的默认格式?

这是我的 config_list.yaml 文件:

title: Properties
modelClass: DP\Properties\Models\Property
list: $/dp/properties/models/property/columns.yaml
recordUrl: 'dp/properties/properties/update/:id'
noRecordsMessage: 'backend::lang.list.no_records'
recordsPerPage: 20
showSetup: true
showCheckboxes: true
defaultSort:
    column: updated_at
    direction: asc
toolbar:
    buttons: list_toolbar
    search:
        prompt: 'backend::lang.list.search_prompt'
filter: config_filter.yaml

这里是 config_filter.yaml 文件的一部分

...
    updated_at:
        label: 'Updated'
        type: daterange
        conditions: created_at >= ':after' AND created_at <= ':before'
        format: d-m-Y
...

还有控制器

class Properties extends Controller
{
    public $implement = [
        'Backend\Behaviors\ListController',
        'Backend\Behaviors\FormController',
        'Backend\Behaviors\ReorderController'
    ];

    public $listConfig = 'config_list.yaml';
    public $formConfig = 'config_form.yaml';
    public $reorderConfig = 'config_reorder.yaml';

    public function __construct()
    {
        parent::__construct();
        BackendMenu::setContext('DP.Properties', 'main-menu-item');
    }

【问题讨论】:

  • 你能把你的代码贴在list.yaml和controller.php中吗?
  • @PettisBrandon 刚刚用列表和控制器更新了我的问题,请看一下

标签: octobercms


【解决方案1】:

10 月的默认日期格式与系统的区域设置相关。 (在后端)。

要更改默认日期格式,请单击右上角的用户头像,然后单击“后端首选项”。默认语言环境将设置为英语(美国)。您可以将其更改为您想要的任何内容。英语(英国)应解析默认的日期格式。但我相信只有美国使用 m/d/Y 格式

【讨论】:

  • 虽然这对于拥有管理员权限的管理员来说是正确的,但这对其他组不可用。我发现您可以通过编辑 /config/cms.php 文件中的 'backendTimezone' 属性为所有用户更改它
【解决方案2】:

您可以通过编辑 /config/cms.php 文件中的“backendTimezone”属性并添加您的时区来更改所有后端表单使用的默认时区。

【讨论】:

    猜你喜欢
    • 2019-08-19
    • 2011-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-17
    • 1970-01-01
    • 1970-01-01
    • 2017-08-23
    相关资源
    最近更新 更多