/** * 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); } }