1

I want to get data by current url, please see my code

 if (currenturl = 'https://example.com/delhi.html') {
                       $_GET['location'] = 289;
    }

but is not giving data while if we run like

https://example.com/delhi.html?location=289

then it is getting data. please anyone idea for that

1
  • What function are you using to get direct url? Commented Dec 27, 2017 at 6:04

1 Answer 1

1

You can get query string of url from below way in phtml file directly,

echo $this->request->getParam('location');

OR

If you want to get current url parameter in block file, need to do using construct parameter,

public function __construct(
    \Magento\Framework\App\Request\Http $request
) {
    $this->request = $request;
}

public function getParamsUrl(){
    return $this->request->getParam('location');
}
1
  • Thanks for your replay. actually i am doing this code in my custom observer in magento2. and getting current url and and i want to pass query string "?location=289" in url : example.com/delhi.html - when we hit this in browser. can you please check for add querystring to this url and then page will load Commented Dec 27, 2017 at 6:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.