artvys/cake-search
最新稳定版本:1.0.0
Composer 安装命令:
composer require artvys/cake-search
包简介
CakePHP adapter for artvys/search package
README 文档
README
This package is CakePHP adapter for the package artvys/search. It provides few boilerplate classes to make integration with framework breeze.
1. Installation
This section describes installation of this package. If you have composer installed, then simply run:
composer require artvys/cake-search
You don't need to install the core package separately. It will be installed automatically.
2. Implementing your TableSearchSource
This package provides you base class TableSearchSource that includes boilerplate code for searching in Table classes from CakePHP.
To use it, you need to extend it and implement 3 abstract methods:
use App\Model\Entity\Article; use Artvys\Search\Cake\Engines\Compiled\SearchSources\Table\TableSearchSource; class ArticlesTableSearchSource extends TableSearchSource { protected function table(): Table { return TableRegistry::getTableLocator()->get('Articles'); } protected function fields(SearchFieldBuilder $builder, CompiledQuery $query, int $limit): void { $builder->add(Field::contains('title')) ->add(Field::contains('body')); } protected function makeResultMapper(): callable { return fn(Article $a) => SearchResult::make($a->title, $a->body, Router::url(['controller' => 'Articles', 'action' => 'edit'])); } }
Those methods do 3 simple things. You need to specify which Table will be searched, which columns will be used and how
to convert instances of entities to SearchResult. Please note that you don't need to use TableRegistry or Router
directly. You can inject your dependencies and then just return them in those required methods.
Take look through the base classes. They contain a lot of little methods meant for extension and can prove to be quite handy for a lot of common use cases.
3. Where to go from here?
The rest of the documentation can be found in the core package artvys/search.
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-05-10