class tools {
public static function getIdByLangCode($languageCode) {
$modx = self::getMODX(); //this is how I get an instance of modx, working and tested
$lang = $modx->getObject('linguaLangs',
array('lcid_string' => $languageCode));
if (empty($lang)) {
error_log('Could not find Lang');
return 0;
}
return $lang->get('id');
}
public static function displayAllIds() {
$lanCodes = ("fr-fr","es-es","de-de");
foreach ($lanCodes as $code){
$output .= self::getIdByLangCode($code);
}
return $output;
}
public static function getMODX(){
$MODX_CORE_PATH= 'c:/wamp/www/modx/core/';
include_once $MODX_CORE_PATH .'model/modx/modx.class.php';
$modx= new modX();
$modx->initialize('mgr');
return $modx;
}
}
[2015-10-20 13:35:48] Could not get table class for class: linguaLangs
[2015-10-20 13:35:48] Could not get table name for class: linguaLangs
[2015-10-20 13:35:48] Error 42000 executing statement:
Array
(
[0] => 42000
[1] => 1064
[2] => You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS `linguaLangs` WHERE `linguaLangs`.`lcid_string` = 'es-es'' at line 1
)This question has been answered by multiple community members. See the first response.
var $modx;
__construct(&$modx) {
$this->modx =& $modx;
}
I'm not sure if it will solve your problem, but the usual way to handle access to the $modx object is to create a $modx class variable and send $modx as a reference argument to the class constructor and make the methods that need it non-static.
var $modx; __construct(&$modx) { $this->modx =& $modx; }
Then you can use $this->modx anywhere in the class.
By using your getMODX() method, you're creating a new instance of MODX every time that method is called -- there should be only one $modx object.
Also, if this is being used in a snippet or plugin, $modx will already be available, so there's no need to instantiate it.
Make sure you don't have a new modX() in there somewhere.
I don't know what else might cause that. You could try adding addPackage() or loadClass() at the top of your code or just above wherever the error is occurring.