【问题标题】:Prevent CakePHP to create div with input field防止 CakePHP 使用输入字段创建 div
【发布时间】:2016-07-19 12:11:08
【问题描述】:

每次我使用创建输入字段时

$this->Form->input('name');

它创建一个 div 元素

<div class="input name">
  <input type="text">
</div>

有没有办法防止在输入字段周围创建 div 块。另外,有没有办法将自定义类添加到创建的div?喜欢

<div class="input name myStyle">
  <input>
</div>

我正在使用CakePHP 3.2

【问题讨论】:

    标签: cakephp form-helpers cakephp-3.2


    【解决方案1】:

    您需要覆盖模板。你可以通过创建一个新的配置文件来做到这一点:

    config/app_form.php

    return [
        'inputContainer' => '{{content}}'
    ];
    

    然后将其加载到您的视图中:

    src/View/AppView.php

    class AppView extends View
    {
        public function initialize()
        {
            parent::initialize();
    
            $this->loadHelper('Form', ['templates' => 'app_form']);
        }
    }
    

    http://book.cakephp.org/3.0/en/views/helpers/form.html#customizing-the-templates-formhelper-uses

    【讨论】:

    • 我想要这个元素。在视图中添加它会影响整个应用程序中的所有表单?我只希望在一个输入字段上使用这个
    • @anujsharma9196 然后你可以做$this-&gt;Form-&gt;input('name', [ 'templates' =&gt; [ 'inputContainer' =&gt; '{{content}}' ] ]);
    【解决方案2】:
    php echo $this->Form->create($user, ['type' => 'file', 'id'=>"change-profile-form",'role' => 'form','class'=>'orb-form']);
    
    $this->Form->templates(['inputContainer' => '{{content}}']);
    
    
    echo $this->Form->input('first_name', ['label'=>false, 'div'=>false, 'placeholder' => 'First name']);
    

    希望对你有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-09
      • 2013-09-09
      • 1970-01-01
      • 2021-09-01
      • 2016-01-25
      • 2015-10-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多