how to pass params to components
Notice: This thread is very old.
- alnux
- Member | 139
hi there,
I dont know how to pass params to my components.
I have this component
protected function createComponentResetPass($hash)
{
return $this->forms->getUserRegistry()->resetPass();
}
and the url is
http://nette.start/homepage/resetpass?hash=lgHBGMYoqlcxC6K2VPgjWEEuT0bnZS1r_1424467048
but as you know the method is protected, the question is how to pass it
- Oli
- Member | 1215
The first param of createComponent is name of this component. I will do it like this
public function actionRestPass($hash)
{
$this->hash = $hash
}
protected function createComponentResetPass()
{
return $this->forms->getUserRegistry()->resetPass($this->hash); // or ->setHash($this->hash)
}
- rp
- Member | 20
My understanding is that you need to reset someone's password. I would probably use an action of the presenter:
<?php
public function actionResetPass($hash)
{
$this->passwordModel->resetPassword($hash);
$this->redirect(/* e.g. 'this' */);
}
?>
If you have encapsulated password logic in a component, then you might set its params in a render method of the presenter that receives the request:
<?php
public function renderRestPass($hash)
{
$this["resetPass"]->setHash($hash);
}
protected function createComponentResetPass()
{
// $hash has been already set through component's setHash method
}
?>