O
O
on_click2019-03-03 02:24:33
opencart
on_click, 2019-03-03 02:24:33

Why can't I get the search request in the module controller inside the public function index()?

It is necessary to add ajax search to the site and push the search by category into it.
I found a suitable search module - link
And everything seems to be clear, but I can't get the search query inside the public function index()
Below it is passed, for example, like this:

public function searchresults(){
        if(isset($this->request->get)){
            $keyword=$this->request->get['keyword'];
        }else{
            $keyword='';
        }

For me, $this->request->get doesn't even come close to what I need.
Please tell me why is this happening? Why does it not work specifically in this place (inside the public function index()) when there are functions below in which this piece of code works fine?
public function getAutocomplite(){
        if(isset($this->request->get)){
            $keyword=$this->request->get['keyword'];
        }else{
            $keyword='';
        }

        $result=$this->model_extension_module_d_ajax_search->autocomplite($keyword);
        $this->response->setOutput(json_encode($result));
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
zoozag, 2019-03-03
@on_click

There is a suspicion that you are doing something wrong, or do not quite understand how the functions in the controller are called.
public function searchresultsand public function getAutocomplite()work because they are accessed at these addresses:
index.php?route=extension/module/d_ajax_search/getAutocomplite&keyword=keyword
index.php?route=extension/module/d_ajax_search/searchresults&keyword=keyword
Accordingly, there is a keyword parameter in the request, which you can get via $this->request->get['keyword']
If you have an empty $this->request->get['keyword'] when accessing the index, then you don't have a get parameter either.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question