Cakephp如何创建简单的搜索表单

时间:2014-04-10 11:39:01

标签: cakephp cakephp-2.0

我需要一些帮助来创建一个带有一个输入框的简单搜索表单。它需要能够将值发送到URL中的控制器,如下所示:

http://mysite.co.uk/properties/results?search=northampton

我想使用cakePHP表单助手,但是你可以包含一个与数据库中的列无关的输入吗?

1 个答案:

答案 0 :(得分:3)

从此找到了答案:

///in the view:///
    <div class="container">
    <a href='#'><div class="search-tab active_search_tab">Property Search</div></a>

    <div class="col-md-12 purple search_box">
    <?php
    echo $this->Form->create('Properties', array('type' => 'get'));
    echo $this->Form->input('search', array('between'=>'<label for="search" class="main_search">Search</label><br>','label'=>false));
    echo $this->Form->button('Search', array('class'=>'btn btn-success'));
    echo $this->Form->end
    ?>
    </div>
    </div>




//in the controller//
    if(isset($this->params['url']['search'])){  
    echo 'search text has been found';
    }

公平评论burzum