Problém s novým quickstartem
Upozornění: Tohle vlákno je hodně staré a informace nemusí být platné pro současné Nette.
- Ecrazit
- Člen | 16
Zdravím,
měl jsem hotovou menší aplikaci podle staršího quickstartu, nyní koukám že se v aktuálním quickstartu trochu jinak řeší modely a předělal jsem zedy svoje modely podle něj. Základem je tedy třída Table, od které dědí další modely. Když se ale pokusím udělat jakýkoli úkon s databází, dostanu hlášku „Call to a member function table() on a non-object“.
- Ecrazit
- Člen | 16
Users.php
<?php
use Nette\Utils\Strings,
Nette\Security as NS;
class Users extends Table {
protected $tableName = 'users';
private $salt;
public function __construct($salt) {
$this->salt = $salt;
}
public function findUser(array $by = NULL) {
return $this->findAll()->where($by)->fetch();
}
public function calculatePasswordHash($password) {
return hash('sha512', $password);
}
public function createIdentity($row) {
return new NS\Identity($row->id, $row->role, array(
'username' => $row->username,
'email' => $row->email,
));
}
}
Table.php viz https://github.com/…el/Table.php
Authenticator.php
<?php
use Nette\Security as NS,
Nette\Utils\Validators;
class Authenticator extends Nette\Object implements NS\IAuthenticator {
private $users;
private $salt;
public function __construct(Users $users, $salt) {
$this->users = $users;
$this->salt = $salt;
}
public function getSalt() {
return $this->salt;
}
public function authenticate(array $credentials) {
list($identificator, $password) = $credentials;
if (Validators::isEmail($identificator)) {
$row = $this->users->findUser(array('email' => $identificator));
}
else {
$row = $this->users->findUser(array('username' => $identificator));
}
if (!$row) {
throw new NS\AuthenticationException('Uživatelské jméno ani e-mail ' . $identificator . ' nebyly nalezeny.', self::IDENTITY_NOT_FOUND);
}
if ($row->password !== $this->users->calculatePasswordHash($password . $this->getSalt())) {
throw new NS\AuthenticationException('Špatně zadané heslo.', self::INVALID_CREDENTIAL);
}
return $this->users->createIdentity($row);
}
}
Jakmile se pokusím přihlásit, skončí to na
protected function getTable()
{
return $this->connection->table($this->tableName);
}
s hláškou Call to a member function table() on a non-object.