[SOLVED] Obtain a module object reference cmsms 1.10.3

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
nervino
Power Poster
Power Poster
Posts: 448
Joined: Sun Dec 28, 2008 12:15 pm
Location: Roma, Italy

[SOLVED] Obtain a module object reference cmsms 1.10.3

Post 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
Last edited by nervino on Mon Feb 20, 2012 12:18 pm, edited 1 time in total.
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1968
Joined: Mon Jan 29, 2007 4:47 pm

Re: Obtain a module object reference cmsms 1.10.3

Post 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();
......
}
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
nervino
Power Poster
Power Poster
Posts: 448
Joined: Sun Dec 28, 2008 12:15 pm
Location: Roma, Italy

Re: Obtain a module object reference cmsms 1.10.3

Post by nervino »

Yes, it works.

Thank you very much.
Post Reply

Return to “Developers Discussion”