UserManager->add() – registracia
Upozornění: Tohle vlákno je hodně staré a informace nemusí být platné pro současné Nette.
- Takeshi
- Člen | 596
ahojte,
ako sa napojim na metodu ->add() v triede UserManager?
skusil som viacero veci ale neviem … ukazuje chybu
<?php
use App\Model;
...
/** @var \App\Model\UserManager @inject */
public $userManager;
public function formSucceeded(Form $form)
{
$data = $form->getValues();
$this->userManager->add($data['username'],$data['password']);
?>
chyba >> Call to a member function add() on a non-object
- Takeshi
- Člen | 596
David Matějka napsal(a):
ten, ktery si poslal
Prepac, ale nechapem na ktory kod sa pytas … tak skusim este raz..
mam vytvoreny formular, po jeho spravnom vyplneni sa snazim registrovat uzivatela cey funkciu, ktora je v triede UserManager
<?php
public function formSucceeded(Form $form)
{
$data = $form->getValues();
$this->userManager->add($data['username'],$data['password']);
?>
tu mi ale ukazuje chybu
No a ta funkcia ->add() v UserManager.php
<?php
public function add($username, $password)
{
try {
$this->database->table(self::TABLE_NAME)->insert(array(
self::COLUMN_NAME => $username,
self::COLUMN_PASSWORD_HASH => Passwords::hash($password),
));
} catch (Nette\Database\UniqueConstraintViolationException $e) {
throw new DuplicateNameException;
}
}
?>
- David Matějka
- Moderator | 6445
v jake tride mas tento kod?
/** @var \App\Model\UserManager @inject */
public $userManager;
public function formSucceeded(Form $form)
{
$data = $form->getValues();
$this->userManager->add($data['username'],$data['password']);
- Takeshi
- Člen | 596
tento kod je v triede RegisterFormFactory
<?php
<?php
namespace App\Forms;
use Nette;
use Nette\Http\Session;
use Nette\Application\UI\Form;
use App\Model;
use Nette\Security\Passwords;
class RegisterFormFactory extends Nette\Object
{
public function create()
{
$form = new Form;
$form->addText('username', 'Jméno');
$form->addText('email', 'E-mail: *', 35)
->setEmptyValue('@')
->addRule(Form::FILLED, 'Vyplňte Váš email')
->addCondition(Form::FILLED)
->addRule(Form::EMAIL, 'Neplatná emailová adresa');
$form->addPassword('password', 'Heslo: *', 20)
->setOption('description', 'Alespoň 6 znaků')
->addRule(Form::FILLED, 'Vyplňte Vaše heslo')
->addRule(Form::MIN_LENGTH, 'Heslo musí mít alespoň %d znaků.', 6);
$form->addPassword('password2', 'Heslo znovu: *', 20)
->addConditionOn($form['password'], Form::VALID)
->addRule(Form::FILLED, 'Heslo znovu')
->addRule(Form::EQUAL, 'Hesla se neshodují.', $form['password']);
$form->addSubmit('send', 'Registrovat');
$form->onSuccess[] = array($this, 'formSucceeded');
return $form;
}
/** @var \App\Model\UserManager @inject */
public $userManager;
public function formSucceeded(Form $form)
{
$data = $form->getValues();
$this->userManager->add($data['username'],$data['password']);
}
}
?>
- David Matějka
- Moderator | 6445
@inject
property jsou defaultne funkcni pouze v presenterech.
pouzij namisto toho konstruktor injection: https://doc.nette.org/…dependencies