【发布时间】:2018-07-03 17:23:57
【问题描述】:
使用PlumSearch插件,它的文档中提到我们可以修改'label':
formConfig:包含 Form::input $options 设置,例如类、输入类型、标签名称...
在我的控制器/initialize() 中,我需要更改一些字段的标签(“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'));
但我无法确定代码的位置和方式。
有什么帮助吗?
【问题讨论】:
-
从文档看来你必须做类似
['name' => 'ip_address', 'className' => 'Input', 'formConfig' => ['label' => 'IP Address']], -
谢谢@arilia。成功了!
标签: cakephp plugins cakephp-3.x