Nefunguje pripojeni k dibi
- tomasnikl
- Člen | 137
Ahoj, s nette se teprve seznamuji, tak to zkusim vzit strucne a snad na nic nezapomenu.
Zkousim si vytvorit jednoduche prihlasovani uzivatelu pres MySQL databazi s vyuzitim dibi.
v config.neon mam toto:
#
# SECURITY WARNING: it is CRITICAL that this file & directory are NOT accessible directly via a web browser!
#
# If you don't protect this directory from direct web access, anybody will be able to see your passwords.
# https://nette.org/en/security-warning
#
common:
php: # PHP configuration
date.timezone: Europe/Prague
# session.save_path: "%tempDir%/sessions"
# zlib.output_compression: yes
services:
robotLoader:
run: true
model:
class: Model
arguments: [@database]
connection:
class = DibiConnection
option: ['%db%']
authenticator:
class: MyAuthenticator
arguments: [@connection]
production < common:
db:
driver = mysql
hostname = "localhost"
username = "root"
password = ""
database = "test"
charset = "utf8"
development < common:
db:
driver = mysql
hostname = "localhost"
username = "root"
password = ""
database = "test"
charset = "utf8"
console < common:
v bootstrap.php (snad to je to dulezite):
$configurator = new Nette\Configurator;
$configurator->container->params += $params;
$configurator->container->params['tempDir'] = __DIR__ . '/../temp';
$container = $configurator->loadConfig(__DIR__ . '/config.neon');
v modelu Authenticator.php toto:
<?php
use Nette\Security as NS;
class MyAuthenticator extends Nette\Object implements NS\IAuthenticator
{
private $connection;
function __construct($connection)
{
$this->connection = $connection;
}
function authenticate(array $credentials)
{
list($username, $password) = $credentials;
$row = dibi::fetchAll('
SELECT *
FROM [users]
WHERE [id] = 1
ORDER BY [ord]', dibi::ASC
);
/* atd atd atd atd */
}
}
a po odeslani prihlasovaciho formulare mi to pise chybu
File: …\libs\dibi\dibi.php Line: 231
231: throw new DibiException(‚Dibi is not connected to
database.‘);
Kde delam chybu prosim Vas?
- studna
- Člen | 181
Achjo. Zajímalo by mě (jestli si to opisoval), tak proč si špatně opsal tu metodu authenticate? Nebo jak si k tomu došel, že si v configu správně nastavíš služby, do MyAuthenticatoru injektuješ připojení a v oné metodě si na něj ani nesáhneš, místo toho je tam nesmyslně statické dibi::fetch() – ano, v tom je ta chyba. ;)
Editoval studna (19. 8. 2011 22:13)