Skip to content

Instantly share code, notes, and snippets.

@shinesoftware
Created June 17, 2014 09:22
Show Gist options
  • Save shinesoftware/d7a758395e93c087d2bf to your computer and use it in GitHub Desktop.
Save shinesoftware/d7a758395e93c087d2bf to your computer and use it in GitHub Desktop.
This is a sample of the search method to be created in the service module in order to use the search engine of the project.
/**
* @inheritDoc
*/
public function search($search, $locale="en_US")
{
$result = array();
$i = 0;
$records = $this->tableGateway->select(function (\Zend\Db\Sql\Select $select) use ($search, $locale){
$select->join('cms_page_category', 'category_id = cms_page_category.id', array ('category'), 'left');
$select->join('base_languages', 'language_id = base_languages.id', array ('locale', 'language'), 'left');
$select->where(new \Zend\Db\Sql\Predicate\Like('title', '%'.$search.'%'));
$select->where(new \Zend\Db\Sql\Predicate\Like('content', '%'.$search.'%'), 'OR');
});
foreach ($records as $record){
$result[$i]['icon'] = "fa fa-file";
$result[$i]['section'] = "Cms";
$result[$i]['value'] = $record->getTitle();
$result[$i]['url'] = "/cms/" . $record->getSlug() . ".html";
$result[$i]['keywords'] = $record->getTags();
$i++;
}
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment