CakePHP搜索两列

时间:2015-08-27 17:52:03

标签: php jquery cakephp

我有搜索表单,当我搜索标题并且类别运行良好但我想使用输入search搜索也抛出描述

这是我的搜索表单:



<div class="search" id="search-mobil" style="padding: 40px 0 30px 0;">
                 
          <?= $this->Form->create($multimedia, ['class' => 'search-wrapper-mobil cf', 'controller' => 'multimedia', 'action' => 'search', 'type' => 'get']); ?>
          
          <?= $this->Form->input('search', ['placeholder' => 'Search your material', 'label' => false]); ?>
          
          
                
        <div style="padding: 50px 0 10px 0; margin-left: 10%; text-align: left;">
        <div class="col-sm-3">
              <input type="radio" name="radio" id="radio4" value="1">
              <label for="radio4">Product Shots</label>
            </div>
            <div class="col-sm-3">
              <input type="radio" name="radio" id="radio5" value="2">
              <label for="radio5">Video</label>
            </div>
            <div class="col-sm-3">
              <input type="radio" name="radio" id="radio6" value="3">
              <label for="radio6">Printing Materials</label>
            </div>
    </div>
          
          <div style="margin: 0 auto; padding-bottom:20px;">
              <?= $this->Form->input('category_id', ['class' => 'electdown-mobil',
                                                               'label' => false,
                                                               'empty' => 'Categories',
                                                               'default' => 'Categories',
                                                               'options' => $categories
                                                              ]); ?>
          </div>
      
                    
        <button type="submit">Search</button>
          
          <?= $this->Form->end(); ?>

  </div>   
&#13;
&#13;
&#13;

我的搜索功能:

    public function search(){

            $multimedia = array();

    if (!empty($this->request->query)) {

        $query = $this->request->query['search'];
        $category_id = $this->request->query['category_id'];
        $multimedia_type_id = $this->request->query['multimedia_type_id'];

        $conditions = array(

            'conditions' => array(            
            'and' => array()));

        if ($query) $conditions['conditions']['and']['Multimedia.title LIKE'] = "%$query%";
        if ($category_id) $conditions['conditions']['and']['Multimedia.category_id'] = $category_id ;
        if ($multimedia_type_id) $conditions['conditions']['and']['Multimedia.multimedia_type_id'] = $multimedia_type_id ;


        $multimedia = $this->Multimedia->find('all', $conditions);
    }
    $this->set('multimedia', $multimedia);

    $categories = $this->Multimedia->Categories->find('list', ['limit' => 200]);
    $users = $this->Multimedia->Users->find('list', ['limit' => 200]);
    $multimedia_types = $this->Multimedia->Multimedia_types->find('list', ['limit' => 200]);
    $this->set(compact('multimedia', 'categories', 'users', 'multimedia_types'));
    $this->set('_serialize', ['multimedia']);

}

此外,我想使用单选按钮在我的表multimedia_types

中搜索

1 个答案:

答案 0 :(得分:0)

部分答案,我意识到我必须将name="radio"更改为name="multimedia_type_id",现在单选按钮正常工作