Page 1 of 1

[SOLVED] Obtain a module object reference cmsms 1.10.3

Posted: Mon Feb 20, 2012 11:56 am
by nervino
Hi All,
I'm upgrading a module I was developing with cmsms 1.9.4.3 but I have a problem with an ajax file that writes in the db.
I make the ajax call from a module's template (.tpl).

My old, working, code in the ajax.php file:

Code: Select all

<?php
require '../../include.php';

$db=&$GLOBALS["gCms"]->db;

global $gCms;

if (!isset($gCms)) exit;

if (isset($gCms->modules['MyModule'])) {
  $mymodule =& $gCms->modules['MyModule']['object'];
  echo "Module OK";
}
If I call directly the ajax page, in cmsms 1.9.4.3, I can read the string "Module OK".


I've changed the code to obtain my module object reference, using the cms_utils::get_module() method:

Code: Select all

<?php

require '../../include.php';

$db=&$GLOBALS["gCms"]->db;

global $gCms;

if (!isset($gCms)) exit;

if (isset(cms_utils::get_module('MyModule')) {

$mymodule = cms_utils::get_module('MyModule');

echo "Module OK";
}
If I call directly the ajax page, in cmsms 1.10.3, I cannot read the string "Module OK" and I got no reference to my module.

What am I doing wrong?

Thank you

Re: Obtain a module object reference cmsms 1.10.3

Posted: Mon Feb 20, 2012 12:03 pm
by Jo Morg
Maybe this will work:

Code: Select all

$gCms = cmsms();

if (!isset($gCms)) exit;

$mymodule =cms_utils::get_module('MyModule')

if (is_object($mymodule) {
#module instance exists do foo....
$mymodule->foo();
......
}

Re: Obtain a module object reference cmsms 1.10.3

Posted: Mon Feb 20, 2012 12:17 pm
by nervino
Yes, it works.

Thank you very much.