Answer the question
In order to leave comments, you need to log in
How to implement search by synonyms?
I use the autocomplete widget to search the table of games and the table of synonyms. For games, the search works, the problem is when searching in the field by synonym. Tell me, how can I connect the search and by synonyms? There is very little information in the docs. Here is the code:
<?php $data = Game::find()
->select([
'game.name as value',
'game.name as label',
'game.id as id',
'synonym.name as name'
])
->leftJoin('game_synonym', 'game_synonym.game_id = game.id')
->leftJoin('synonym', 'synonym.id = game_synonym.synonym_id')
->asArray()
->all(); ?>
<?= AutoComplete::widget([
'name' => 'Company',
'id' => 'ddd',
'clientOptions' => [
'source' => $data,
'autoFill' => true,
'minLength' => '1',
'maxShowItems' => 5,
'select' => new JsExpression("function( event, ui ) {
$('#game').val(ui.item.id);
}"),
],
'options' => [
'class' => 'game-input',
'placeholder' => '*Название игры',
],
]);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question