Search for information in the project database
app/Plugin/CakeSearchInfo/Config/cakesearchinfo.php
to app/Config
.Example of configuration file
Include component CakeSearchInfo.SearchFilter
in your AppController
:
public $components = [
'CakeSearchInfo.SearchFilter'
];
app/Plugin/CakeSearchInfo/Locale/rus/LC_MESSAGES/cake_search_info.*
to
app/Locale/rus/LC_MESSAGES
/cake_search_info/search
or simply /search
Include helper CakeSearchInfo.Search
in your AppController
:
public $helpers = [
'CakeSearchInfo.Search'
];
Add in your layout
:
echo $this->Html->script('CakeSearchInfo.SearchInfo.min.js');
echo $this->Html->css('CakeSearchInfo.SearchInfo.min.css');
echo $this->Search->createFormSearch($search_targetFields, $search_targetFieldsSelected, $search_urlActionSearch, $search_targetDeep, $search_querySearchMinLength);
Add in your Controller
method:
/**
* Action `index`. Used to begin search.
*
* @return void
*/
public function index() {
$search_urlActionSearch = ['controller' => 'some_controoler', 'action' => 'search'];
$this->set(compact('search_urlActionSearch'));
}
/**
* Action `search`. Used to view a result of search.
*
* @return void
*/
public function search() {
$whitelist = [];
$this->SearchFilter->search($whitelist);
}
$config['CakeSearchInfo'] = [
'QuerySearchMinLength' => 0,
'AutocompleteLimit' => 10,
'TargetDeep' => 0,
'DefaultSearchAnyPart' => true,
'TargetModels' => [
/*
'ModelName' => [
'fields' => [
'ModelName.FieldName' => __('Field name'),
'ModelName.FieldName2' => __('Field name 2'),
],
'order' => ['ModelName.FieldName' => 'direction'],
'name' => __('Scope name'),
'recursive' => 0, // not necessary - default: -1
'contain' => null, // not necessary - default: null
'conditions' => ['ModelName.FieldName' => 'SomeValue'], // not necessary - used as global conditions
'url' => [
'controller' => 'modelnames',
'action' => 'view',
'plugin' => 'pluginname',
], // not necessary - used in link to result
'id' => 'ModelName.id', // not necessary - used in link to result
],
*/
],
'IncludeFields' => [
/*
'ModelName' => [
'ModelName.FieldName',
'ModelName.FieldName2',
]
*/
],
];