When I try to access data in an xPDO db object
in a FormIt preHook, the thing crashes and I get no output. Because of that I keep resorting to non-xPDO database calls in all of my preHooks (which I use to prefill some forms with values).
Here is the snippet I call first in the preHook to load the db into the $modx object (formerly, a $modx placeholder).
<?php
//$db = $modx->getPlaceholder('inventar.db');
//if (!($db instanceof xPDO)) {
$host = 'localhost';
$port = 3306;
$database = 'inventar';
$username = 'user';
$password = 'password';
$dsn = "mysql:host=$host;port=$port;dbname=$database";
$db = new xPDO($dsn, $username, $password);
$db->addPackage('Inventardatenbank','/var/www/core/components/Inventardatenbank/model/','');
//$modx->setPlaceholder('inventar.db', $db);
$modx->inventar_db = & $db;
//}
return '';
Here is the preHook I'd like to use. The bit that makes the whole thing crash is $aussteller->get('Aussteller') - but only here, in preHooks. Everywhere else the same code works fine.
<?php
if(isset($_GET["auid"])) {
$renr = $_GET["auid"];
$hook->setValue('auid',$auid);
}
$modx->runSnippet('getInventarConnection');
$db = & $modx->inventar_db;
if (!empty($db)) {
$aussteller = $db->getObject('Aussteller',$auid);
$hook->setValue('auid',$auid);
$hook->setValue('auname',$aussteller->get('Aussteller'));
}
return true;
Thanks alot for your help!
René
[ed. note: neo2.0 last edited this post 14 years, 2 months ago.]