as the title says I need to highlight the input string of a search in the results, I mean if I look for "ome" the results should look like this:
Searching on the documentation I have found that I need to activate the "Text" helper and that I should have a code similar to this:
echo $this->Text->highlight($string);
Even though I've tried many possibilities, I can not make it work, I know "Text" helper is working because this works for me at View/Users/index.ctp:
echo $this->Text->autoLinkEmails(h($user['User']['email']));
if it helps, this is the code I've generated for the search which works correctly:
file: Model/Oldcaterm.php
public $actsAs = array(
'Search.Searchable'
);
public $filterArgs = array(
'entry' => array(
'type' => 'like',
'field' => array('entry', 'lemma_tag')
),
'lemma_tag' => array(
'type' => 'like',
'field' => array('entry', 'lemma_tag')
),
);
file: Controller/OldcatermsController.php
public function index() {
$this->Oldcaterm->recursive = 0;
$this->Prg->commonProcess();
$this->Paginator->settings['conditions'] = $this->Oldcaterm->parseCriteria($this->Prg->parsedParams());
$this->set('terms', $this->Paginator->paginate());
}
file: View/Oldcaterms/index.ctp
<?php
echo $this->Form->create(null,array());
echo $this->Form->input('entry', array('label' => 'Cerca coincidència'));
echo $this->Form->end(__('Submit'));
?>
I have read and try many differents ways, but I'm not able to make it work, can somebody please guide me a little, I have found next example at the documentation:
// called as TextHelper
echo $this->Text->highlight(
$lastSentence,
'using',
array('format' => '<span class="highlight">\1</span>')
);
// called as String
App::uses('String', 'Utility');
echo String::highlight(
$lastSentence,
'using',
array('format' => '<span class="highlight">\1</span>')
);
But I don't find the way to make it fit into my code
Thanks in advance.
After a few studies, I realized the css style is not there. Right click on your browser and explore the source code, if it shows <span class="highlight">Your Text Here</span>
then everything is just right. Just add followings code to your CSS file
.highlight{ background-color: #FFDF00; /* <-- Choose what colour you want to use. Here is Golden Yellow */ }
If you still have any problem, please share in the comment.