Ejemplo n.º 1
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if ($this->items === null) {
         throw new InvalidConfigException('映射搜索组件缺少items选项值参数!是否书写错误?');
     }
     $this->items = Universal::getCallableValue($this->items);
 }
Ejemplo n.º 2
0
 /**
  * 获取被搜索组件解析过的查询对象
  * 
  * @param array $searchAttributes 搜索属性
  * @param Model $searchModel 搜索模型
  * @param \yii\base\ActiveQuery $query 列表查询对象
  * @return \yii\base\ActiveQuery 解析过的查询对象
  */
 public static function getSearchQuery(array $searchAttributes, $searchModel, $query)
 {
     $query = Search::create('keywords', 'keywords', $searchModel)->parseQuery($query);
     foreach ($searchAttributes as $attribute => $configs) {
         //关键字组件已经单独解析
         if (isset($configs['type']) && $configs['type'] == 'keywords') {
             continue;
         }
         $type = $configs['type'];
         unset($configs['type'], $configs['label']);
         $query = Search::create($type, $attribute, $searchModel, null, $configs)->parseQuery($query);
     }
     return $query;
 }
Ejemplo n.º 3
0
        <?php 
    //渲染关键字搜索
    $keywordsTypeItems = SearchForm::getDynamicAttributes($searchAttributes, $attributeLabels, 'keywords');
    if (!empty($keywordsTypeItems)) {
        echo Search::create('keywords', 'keywords', $searchModel, $searchForm, ['keywordsTypeItems' => $keywordsTypeItems])->renderHtml();
    }
    //渲染其他搜索
    foreach ($searchAttributes as $attribute => $configs) {
        if (!isset($configs['type'])) {
            throw new InvalidConfigException('搜索属性' . $attribute . '缺少type参数值!');
        }
        if ($configs['type'] == 'keywords') {
            continue;
        }
        $type = $configs['type'];
        unset($configs['label'], $configs['type']);
        echo Search::create($type, $attribute, $searchModel, $searchForm, $configs)->renderHtml();
    }
    ?>
        
        <button class="btn mr10" type="submit">搜索</button>

        <button class="btn" onclick="javascript:window.location.href='<?php 
    echo Url::to(['index']);
    ?>
'" >重置</button>
    </div>
    <?php 
    ActiveForm::end();
}