繁体   English   中英

Cake PHP 3-模板使用无法删除的模板生成div

[英]Cake PHP 3 - template generate div with template that i can't remove

只是一个小问题! 在我的文档中,我返回这样的输入

 return parent::input($fieldName, [ 
    'div'=> false, 
    'label' => [
          'class' => ' control-label col-md-'.$this->getLeft().' '
    ],
    'templates' => [
        'formGroup' => '{{label}} <div class="form-group col-md-'.$this->getRight().'"> {{input}} </div>'
    ], 
    'class' => 'form-control' 
]);

在我的文件中我有类似的东西

<div class="input text required">
    <label class"control-label col-md-3" for="title">Title</label>
        <div class="form-group col-md-9">
            <input type="text" name="title" class="form-control" required="required" maxlength="50" id="title" value="Article premier de la constitution">
        </div>
</div>

真的不想要那个第一个div! 喜欢这样的东西:

<div class="form-group">
    <label class"control-label col-md-3" for="title">Title</label>
        <div class="form-group col-md-9">
            <input type="text" name="title" class="form-control" required="required" maxlength="50" id="title" value="Article premier de la constitution">
        </div>
</div>

我尝试了解模板...那么如何调用我的模板以获得良好的渲染效果? 或者我应该如何处理输入的“ div => false”?

我一点一点进步。 现在,我只是关闭了不需要的div。

删除div的答案:

return parent::input($fieldName, ['label' => ['class' => ' control-label col-md-'.$this->getLeft().' '],
                                  'templates' => ['inputContainer' => '<div class="form-group">{{content}}</div>'], 'class' => 'form-control col-md-9' ]);

}
  • 新问题:如何解析我调用的内容? 因为在我获得“ {{label}}”和“ {{input}}”之前,我不得不将我想要的div放在这两个之间...有人可以告诉我如何将这个{{content}}分解为两个部分?

您应该为助手编辑默认配置。

转到: vendor / cakephp / cakephp / src / View / Helper / FormHelper.php

查找并复制您可以编辑的所有模板结构:

protected $_defaultConfig = [
    ...
    'templates' => [
        'inputContainer' => '<div class="input {{type}}{{required}}">{{content}}</div>',
        ...
    ]
];

去创建文件config / app_form.php

打开app_form.php粘贴结构编辑并制作我们自己的模板

<?php 

return [
   'inputContainer' => '<div class="form-group">{{content}}</div>'

];

现在转到View / AppView.php并编辑初始化函数

 public function initialize()
    {
        $this -> loadHelper('Form', [
            'templates' => 'app_form' //Name of file created in previous step
        ]);
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM