Hello again,
another mystery popped up, and I have absolutely no idea how to handle this.
I have a small database where I store CDs, Licenses, Bills, Archive Numbers and so on. I have "display pages" and "edit pages" for each of these, where the display page should give me a full list of the respective items and the "edit page" for editing such item is linked for each object in the list.
On the edit pages, I use FormIt to call a preHook to load item date into the form and a hook to store the edited data, so nothing exotic here. In some of my "display" snippets, I use the following code without problems:
$modx->runSnippet('getInventarConnection');
$db = & $modx->inventar_db;
...
$cd = $db->getObject('CDs',1);
...
where getInventarConnection has the following code:
$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->inventar_db = & $db;
return '';
Now using
the same code in a preHook fails,
but only in the case of CDs. The $db->getObject('CDs',1) call returns null, but for any other object returns the requested object. As I said, elsewhere, like in the CDs and Bills display snippets, the same call returns the requested CD.
Note that replacing this call with plain mySQL is a viable but undesirable workaround and has saved me so far.
Does any one suspect what's going on? I certainly don't. I'd love hints on what kind of info to supply for better forensics, by the way.
Thanks for reading!
Update:
I just built some other preHook where the exact same call works fine and dandy. I'm utterly puzzled and investigating deeper.
Update:
I use the following same snippet as preHook in FormIt calls from 2 different resources.
$modx->runSnippet('getInventarConnection');
$db = & $modx->inventar_db;
if (!empty($db)) {
$allecds = $db->getCollection('CDs');
$allebesitzer = $db->getCollection('Besitzer');
print_r($allecds);
}
$modx->log(xPDO::LOG_LEVEL_ERROR,'preHook dummy ' );
exit();
On one page, I get "array ()", on the other I get "array (
loads of stuff indicating the call worked)". This is the FormIt call on the first resource:
[[!FormIt?
&preHooks=`dummy7`
&hooks=`CD-Bearbeitung,redirect`
&redirectTo=`3`
&submitVar=`abschicken`
]]
And this is the call on the second resource:
[[!FormIt?
&preHooks=`dummy7`
&hooks=`RechnungSpeichern,redirect`
&redirectTo=`13`
]]
There's another form on the first resource - maybe that's the culprit?
[ed. note: neo2.0 last edited this post 14 years, 2 months ago.]