getStartsWith() public static method

..
public static getStartsWith ( string $term, string $language = '', integer $limit = 10 ) : array
$term string The first letters of the term we're looking for.
$language string The language to search in.
$limit integer Limit result set.
return array
Beispiel #1
0
 /**
  * Execute the action
  */
 public function execute()
 {
     // call parent, this will probably add some general CSS/JS or other required files
     parent::execute();
     // get parameters
     $charset = $this->getContainer()->getParameter('kernel.charset');
     $searchTerm = \SpoonFilter::getPostValue('term', null, '');
     $term = $charset == 'utf-8' ? \SpoonFilter::htmlspecialchars($searchTerm) : \SpoonFilter::htmlentities($searchTerm);
     $limit = (int) $this->get('fork.settings')->get('Search', 'autocomplete_num_items', 10);
     // validate
     if ($term == '') {
         $this->output(self::BAD_REQUEST, null, 'term-parameter is missing.');
     } else {
         // get matches
         $matches = FrontendSearchModel::getStartsWith($term, FRONTEND_LANGUAGE, $limit);
         // get search url
         $url = FrontendNavigation::getURLForBlock('Search');
         // loop items and set search url
         foreach ($matches as &$match) {
             $match['url'] = $url . '?form=search&q=' . $match['term'];
         }
         // output
         $this->output(self::OK, $matches);
     }
 }