How to get parameters from url in a component?

2 months ago

netteman
Member | 78
+
0
-

Hi,

I figured out I can use Nette\Http\Request in a component to get a parameter from URL.

public function __construct(\Nette\Http\Request $httpRequest){
    $this->httpRequest = $httpRequest;
}
...
$variable = $this->httpRequest->getQuery('a-parameter-from-url');

Is there a better/safer way how to get the parameters? I'd like to avoid getting my parameters in a presenter, passing them to a template and then passing them to a component

{control componentName $a, $b, $c, $d, $e...}

Thanks :)

2 months ago

David Matějka
Moderator | 5972
+
+2
-

You should pass them to the component from createComponent method (usign setter or using factory method)

2 months ago

netteman
Member | 78
+
0
-

David Matějka wrote:

You should pass them to the component from createComponent method (usign setter or using factory method)

Thanks :)