dev-master
9999999-dev https://github.com/ychapard/cakephp3-searchfork from
MIT
The Development Requires
by Yannick CHAPARD-EYROLLE
cakephp search cakephp3 cake3 cakephp3-search
fork from
Search provides a search module for CakePHP applications. Added : * A field ( search_data default) is automatically filled with the values of the fields you want to index * Search word is separated into words (space char) so search is base on multiples words, (*1)
The master branch has the following requirements:, (*2)
php composer.phar require ychapard/cakephp3-search "dev-master"
config/bootstrap.php
Plugin::load('Search');
or running command, (*3)
./bin/cake plugin load Search
use Search\Manager; ... public function searchConfiguration() { $search = new Manager($this); $search ->value('author_id', [ 'field' => $this->aliasField('author_id') ]) ->like('q', [ 'before' => true, 'after' => true, 'field' => [$this->aliasField('title'), $this->aliasField('title')] ]); return $search; }
public function initialize(array $config) { ... $this->addBehavior('Search.Search',[ 'field' => ['name','title','short_text'], 'dest_field' => 'search_data', 'replacement' => ' ' ]); ... }
Article
public function index() { $query = $this->Countries ->find('search', $this->Articles->filterParams($this->request->query)) ->where(['title !=' => null]) ->order(['Article.id' => 'asc']) ->contain([ 'Comments' ]); $this->set('articles', $this->paginate($query)); }
The search
finder and the filterParams()
method are dynamically provided by the
Search
behavior., (*4)
public function index() { $this->loadComponent('Search.Prg'); }
public function initialize() { parent::initialize(); if ($this->request->action === 'index') { $this->loadComponent('Search.Prg'); } }
Once you have completed all the setup you can now filter your data by passing query params in your index method. Using the Article example given above, you could filter your articles using the following., (*5)
example.com/articles?q=cakephp
, (*6)
Would filter your list of articles to any article with "cakephp" in the title
or content
field. You might choose to make a get
form which posts the filter
directly to the url, or create links manually., (*7)
fork from
MIT
cakephp search cakephp3 cake3 cakephp3-search