Registrácia pomocou UserManager
- Takeshi
- Člen | 596
Ahojte,
rozhodol som sa, že vyskúšam registráciu a prihlasovanie pomocou UserManager. Pozeral som pár návodou, aj isté články z tohoto fóra ale narazil som na problém.
Moj register form :
<?php
<?php
namespace App\Presenters;
use Nette,
App\Model;
use Nette\Application\UI,
Nette\Application\UI\Form as Form;
class RegisterPresenter extends BasePresenter {
/**
* @var \App\UserManager
* @inject
*/
public $userManager;
protected function startup() {
parent::startup();
}
protected function createComponentRegisterForm() {
$form = new Nette\Application\UI\Form;
$form->addText('username', 'Username:')
->setRequired('Please enter your username.');
$form->addPassword('password1', 'Password:')
->setRequired('Please enter your password.');
$form->addPassword('password2', 'Password again:')
->setRequired('Please enter your password.');
$form->addSubmit('send', 'Register');
$form->onSuccess[] = array($this, 'registerFormSubmitted');
return $form;
}
public function registerFormSubmitted(Form $form) {
$values = $form->getValues();
if($values->password1 == $values->password2){
$user = new $this->userManager;
$user->add($values->username, $values->password1);
$this->flashMessage('You have been registered succesfuly.');
} else {
$this->flashMessage('Something goes wrong, maybe the passwords doesn\'t match.');
}
}
}
?>
Chyba :
<?php
Class or interface 'App\UserManager' used in @var annotation at App\Presenters\RegisterPresenter::$userManager not found. Check annotation and 'use' statements.
?>
Viete mi pomôcť? Ďakujem
Editoval Takeshi (22. 11. 2015 22:04)
- Takeshi
- Člen | 596
Oli napsal(a):
Však to tam máš napsaný. Tvůj $userManager nemá namespace
App
nebo jsi to nedal do configu…
Ďakujem, ale to som si všimol. Ja skôr neviem čo mám urobiť, kde to doplniť.
V config.neon je nasledovné :
<?php
services:
- App\Model\UserManager
- App\Forms\SignFormFactory
?>
A čo sa týka namespace UserManagera, ten má v sebe obsiahnuté nasledovné (bohužiaľ neviem, či je to správne) :
<?php
<?php
...
namespace App\Model;
?>
- Takeshi
- Člen | 596
Oli napsal(a):
Tak tohle je spravne. A ted se podívej do presenteru, kde má byt ‚@var \App\Model\UserManager‘
Tak použil som to, v hore spomenutom, presenteri RegisterPresenter.php, kde by to tiež malo byť správne : ešte raz v skrátenej podobe :
<?php
namespace App\Presenters;
use Nette,
App\Model;
use Nette\Application\UI,
Nette\Application\UI\Form as Form;
class RegisterPresenter extends BasePresenter {
/**
* @var \App\UserManager
* @inject
*/
public $userManager;
...
?>
A keby som zmenil posledné riadky @var … na :
<?php
/**
* @var \App\Model\UserManager
* @inject
*/
public $userManager;
?>
Ukázalo by mi to chybu :
Argument 1 passed to App\Model\UserManager::__construct() must be an instance of Nette\Database\Context, none given, called in C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\projects\Brloh\app\presenters\RegisterPresenter.php on line 41 and defined
- David Matějka
- Moderator | 6445
RegisterPresenter.php on line 41
co mas v tom presenteru na tom radku?
- David Matějka
- Moderator | 6445
proc to tam mas? v $this->userManager
mas intanci te sluzby,
na te pak volas metody jako register
nebo jakou tam mas..