嗨,我是新的堆栈溢出,我通常从别人的问题中找到我的答案。 我想为整个项目配置cakephp表单助手 我想知道我应该把这些配置放在哪里加载整个项目。
我的配置就像这样
$this->Form->setTemplates([
'button' => '<button{{attrs}}>{{text}}</button>' ,
'checkbox' => 'haji' ,
'checkboxFormGroup' => '<label class="col-lg-2 control-label">{{mytitle}}</label><div class="col-md-10"> <div class="md-checkbox-list"><div class=""><input id="checkbox30" class="md-check" type="checkbox">
<label for="checkbox30">
<span></span>
<span class="check"></span>
<span class="box"></span> Option 1 </label></div></div></div>' ,
'checkboxWrapper' => '<div class="aaaaaaaaaaaaaaa">{{label}}</div>' ,
'dateWidget' => '{{year}}{{month}}{{day}}{{hour}}{{minute}}{{second}}{{meridian}}' ,
'error' => '<div class="error-message">{{content}}</div>' ,
'errorList' => '<ul>{{content}}</ul>' ,
'errorItem' => '<li>{{text}}</li>' ,
'file' => '<input type="file" name="{{name}}"{{attrs}}>' ,
'fieldset' => '<fieldset{{attrs}}>{{content}}</fieldset>' ,
'formStart' => '<form class="form-horizontal" {{attrs}}><div class="form-body">' ,
'formEnd' => '</div> </form>' ,
'formGroup' => '{{label}}<div class="col-md-10">{{input}}<div class="form-control-focus"> </div></div>' ,
'hiddenBlock' => '<div style="display:none;">{{content}}</div>' ,
'input' => '<input class="form-control" type="{{type}}" name="{{name}}"{{attrs}}/>' ,
'inputSubmit' => '<input type="{{type}}"{{attrs}}/>' ,
'inputContainer' => '<div class="form-group form-md-line-input">{{content}}</div>' ,
// 'inputContainer' => '<div class="input {{type}}{{required}}">{{content}}</div>' ,
'inputContainerError' => '<div class="input {{type}}{{required}} error">{{content}}{{error}}</div>' ,
'label' => '<label class="col-md-2 control-label" {{attrs}}>{{text}}</label>' ,
'nestingLabel' => '{{hidden}}<label{{attrs}}>{{input}}{{text}}</label>' ,
'legend' => '<legend>{{text}}</legend>' ,
'multicheckboxTitle' => '<legend>{{text}}</legend>' ,
'multicheckboxWrapper' => '<fieldset{{attrs}}>{{content}}</fieldset>' ,
'option' => '<option value="{{value}}"{{attrs}}>{{text}}</option>' ,
'optgroup' => '<optgroup label="{{label}}"{{attrs}}>{{content}}</optgroup>' ,
'select' => '<select class="form-control" name="{{name}}"{{attrs}}>{{content}}</select>' ,
'selectMultiple' => '<select name="{{name}}[]" multiple="multiple"{{attrs}}>{{content}}</select>' ,
'radio' => '<input type="radio" name="{{name}}" value="{{value}}"{{attrs}}>' ,
'radioWrapper' => '{{label}}' ,
'textarea' => '<textarea class="form-control" name="{{name}}"{{attrs}}>{{value}}</textarea>' ,
'submitContainer' => '<div class="">{{content}}</div>' ,
]); ?&GT;
非常感谢。抱歉英语不好
答案 0 :(得分:2)
为模板制作配置文件并将其放在配置文件夹中,您可以根据需要为其命名,在此示例中,表单模板
<强> /config/form-templates.php 强>
<?php
return [
'button' => '<button{{attrs}}>{{text}}</button>' ,
'checkbox' => 'haji' ,
'checkboxFormGroup' => '<label class="col-lg-2 control-label">{{mytitle}}</label><div class="col-md-10"> <div class="md-checkbox-list"><div class=""><input id="checkbox30" class="md-check" type="checkbox">
<label for="checkbox30">
<span></span>
<span class="check"></span>
<span class="box"></span> Option 1 </label></div></div></div>' ,
'checkboxWrapper' => '<div class="aaaaaaaaaaaaaaa">{{label}}</div>' ,
'dateWidget' => '{{year}}{{month}}{{day}}{{hour}}{{minute}}{{second}}{{meridian}}' ,
'error' => '<div class="error-message">{{content}}</div>' ,
'errorList' => '<ul>{{content}}</ul>' ,
'errorItem' => '<li>{{text}}</li>' ,
'file' => '<input type="file" name="{{name}}"{{attrs}}>' ,
'fieldset' => '<fieldset{{attrs}}>{{content}}</fieldset>' ,
'formStart' => '<form class="form-horizontal" {{attrs}}><div class="form-body">' ,
'formEnd' => '</div> </form>' ,
'formGroup' => '{{label}}<div class="col-md-10">{{input}}<div class="form-control-focus"> </div></div>' ,
'hiddenBlock' => '<div style="display:none;">{{content}}</div>' ,
'input' => '<input class="form-control" type="{{type}}" name="{{name}}"{{attrs}}/>' ,
'inputSubmit' => '<input type="{{type}}"{{attrs}}/>' ,
'inputContainer' => '<div class="form-group form-md-line-input">{{content}}</div>' ,
// 'inputContainer' => '<div class="input {{type}}{{required}}">{{content}}</div>' ,
'inputContainerError' => '<div class="input {{type}}{{required}} error">{{content}}{{error}}</div>' ,
'label' => '<label class="col-md-2 control-label" {{attrs}}>{{text}}</label>' ,
'nestingLabel' => '{{hidden}}<label{{attrs}}>{{input}}{{text}}</label>' ,
'legend' => '<legend>{{text}}</legend>' ,
'multicheckboxTitle' => '<legend>{{text}}</legend>' ,
'multicheckboxWrapper' => '<fieldset{{attrs}}>{{content}}</fieldset>' ,
'option' => '<option value="{{value}}"{{attrs}}>{{text}}</option>' ,
'optgroup' => '<optgroup label="{{label}}"{{attrs}}>{{content}}</optgroup>' ,
'select' => '<select class="form-control" name="{{name}}"{{attrs}}>{{content}}</select>' ,
'selectMultiple' => '<select name="{{name}}[]" multiple="multiple"{{attrs}}>{{content}}</select>' ,
'radio' => '<input type="radio" name="{{name}}" value="{{value}}"{{attrs}}>' ,
'radioWrapper' => '{{label}}' ,
'textarea' => '<textarea class="form-control" name="{{name}}"{{attrs}}>{{value}}</textarea>' ,
'submitContainer' => '<div class="">{{content}}</div>'
];
然后在 View / AppView.php 初始化方法中,使用上面的模板配置文件加载表单助手:
public function initialize()
{
parent::initialize();
$this->loadHelper('Form', ['templates' => 'form-templates']);
}