首页 > 解决方案 > cakephp:plumSearch - 在参数中更改过滤器的标签

问题描述

使用 PlumSearch 插件,它的文档中提到我们可以修改“标签”:

formConfig:包含 Form::input $options 设置,如类、输入类型、标签名称...

在我的控制器/初始化()中,我需要更改某些字段的标签(“IP 地址”而不是“IP 地址”,“状态”而不是“资产状态”):

public function initialize()
{
parent::initialize();

$parameters = [
    ['name' => 'serial_number', 'className' => 'Input'],
    ['name' => 'model_number', 'className' => 'Input'],
    ['name' => 'ip_address', 'label' => 'IP Address', 'className' => 'Input'],
];
if ($this->request->param('action') == 'reportFacility') {
    $statuses = $this->AssetsAssignations->AssetStatuses->find('list')->order(['name' => 'asc']);
    $this->set(compact('asset_statuses'));
    $parameters = [
        ['name' => 'asset_status_id', 'className' => 'Select', 'label' => 'Status',
            'finder' => $statuses
        ],
    ];
}   elseif ($this->request->param('action') == 'reportClient') {
    $clients = $this->AssetsAssignations->Clients->find('list')->order(['last_name' => 'asc', 'first_name' => 'asc']);
    $this->set(compact('clients'));
    $parameters = [
        ['name' => 'client_id', 'className' => 'Select', 'label' => 'Client',
            'finder' => $clients
        ],
    ];
} elseif ($this->request->param('action') == 'reportRoom') {
    $rooms = $this->AssetsAssignations->Rooms->find('list')->order(['name' => 'asc']);
    $this->set(compact('rooms'));
    $parameters = [
        ['name' => 'room_id', 'className' => 'Select', 'label' => 'Room',
            'finder' => $rooms
        ],
    ];
}
$this->loadComponent('PlumSearch.Filter', ['parameters' => $parameters]);

}`

上面的代码不适用于标签。

有人告诉我使用以下代码:

 $inputOptions = [
        'search' => [
            'placeholder' => __('Type to search...'),
            'class' => 'form-control',
            'label' => 'Search'
        ]
    ];
    $this->set(compact('inputOptions'));

但我无法确定我的代码中的位置和方式。

请问有什么帮助吗?

标签: cakephppluginscakephp-3.x

解决方案


只是你必须以这种方式将它添加到$parameters数组中

$parameters = [
    /* other fields here */
    [
        'name' => 'ip_address', 
        'className' => 'Input', 
        'formConfig' => ['label' => 'IP Address']
    ],
];

推荐阅读