如何创建搜索框cakephp

How to create Search Box cakephp

我是 CakePHP 的新手...我想在不使用插件的情况下在我的视图页面中动态创建搜索框。

<div class="box-tools">
    <div class="input-group input-group-sm" style="width: 150px;">
        <input type="text" name="table_search" class="form-control pull-right" placeholder="Search">
        <div class="input-group-btn">
            <button type="submit" class="btn btn-default"><i class="fa fa-search"></i></button>
        </div>
    </div>
</div>

您将不得不使用 CakePHP 提供的 Formhelper。 由于您使用的 Bootstrap 需要特定的 div 和 类 输入 fields/containers,您可以使用如下内容:

<?=$this->Form->create('Yourmodel')?>
<div class="box-tools">
    <div class="input-group input-group-sm" style="width: 150px;">
        <?=$this->Form->input('table_search', array('placeholder' => 'Search', 'class' => 'form-control pull-right', 'type' => 'text', 'div' => false, 'label' => false))?>
        <div class="input-group-btn">
            <?=$this->Form->submit('<i class="fa fa-search"></i>', array('escape' => false, 'class' => 'btn btn-default', 'div' => false))?>
        </div>
    </div>
</div>
<?=$this->Form->end()?>