定制 black-lamp/yii2-search 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

black-lamp/yii2-search

最新稳定版本:2.0.2

Composer 安装命令:

composer require black-lamp/yii2-search

包简介

Component for search in Active Record models

README 文档

README

Build Status Latest Stable Version Latest Unstable Version License

Installation

Run command

composer require black-lamp/yii2-search

or add

"black-lamp/yii2-search": "^2.0.0"

to the require section of your composer.json.

Add 'SiteSearch' component to application config

'components' => [
      // ...
      'search' => [
            'class' => bl\search\SearchComponent::class,
            // models where you need the search
            'models' => [
                'article' => [
                    'class' => frontend\models\Article::class,
                    'label' => 'Articles'
                 ],
                // ...
            ]
      ],
]

To models array you should to add the active record models where component will be make a search.

class it's a model's name.

label it's a title for displaying in view.

Implement interface in the models where you need a search

/**
 * @property integer $id
 * @property string $title
 * @property string $shortText
 * @property string $fullText
 * @property string $socialNetworksText
 */
class Article extends ActiveRecord implements \bl\search\interfaces\SearchInterface
{
    // ...

    /**
     * @inheritdoc
     */
    public function getSearchTitle() {
        return $this->title;
    }

    /**
     * @inheritdoc
     */
    public function getSearchDescription() {
        return $this->shortText;
    }

    /**
     * @inheritdoc
     */
    public function getSearchUrl() {
       return Url::toRoute["/articles/$this->id"];
    }

   /**
    * @inheritdoc
    */
    public function getSearchFields() {
        return [
            'title',
            'shortText',
            'fullText'
        ];
    }
}

Using

Call method for getting a search results. This method return a SearchResult objects in array.

/**
 * @var \bl\search\data\SearchResult[] $result
 */
$result = Yii::$app->searcher->search('Black lamp');

foreach($result as $res) {
    $res->title;
    $res->description;
    $res->url;
}

统计信息

  • 总下载量: 205
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2016-09-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固