[SOLVED] Calling other modules from a method

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
larss
New Member
New Member
Posts: 6
Joined: Mon Aug 04, 2008 7:17 am

[SOLVED] Calling other modules from a method

Post by larss »

I'd like to integrate a few linked admin functions for a specific site. In specifics, I'll be linking the creation of a FEU Group with a News category, a Comments category, and others; allowing me to link specific content to a FEU group. This will prevent the admins of the site from repetitive entry. Now I could go through each of the modules methods, combine them into a giant one; but that's not really portable when the News or other modules get updated. Instead I'd like to call the other modules from my linking module action; I'm assuming it's something like:

$gCms->modules['News']->addcategory....

If that's correct, how would the parameters be passed syntax wise?
Last edited by larss on Tue May 19, 2009 5:52 pm, edited 1 time in total.
User avatar
plger
Forum Members
Forum Members
Posts: 196
Joined: Wed Oct 15, 2008 10:38 am

Re: Calling other modules from a method

Post by plger »

Access the module object with:

Code: Select all

$themodule = $this->GetModuleInstance("News")
or:

Code: Select all

$themodule = $gCms->modules['News']['object'];
(and check if it exists and is active before going further)

Then you should be able to access the module's actions with :

Code: Select all

$themodule->DoAction($action, $id, $params, $returnid=-1);
So in your case :
$themodule->DoAction("addcategory",$id,$params,$returnid);
$params being an array containing the "name", and eventually "parent" or anything the action might need...

And of course you should use module events to call your "linking module".

Have a nice day,
plger
larss
New Member
New Member
Posts: 6
Joined: Mon Aug 04, 2008 7:17 am

Re: Calling other modules from a method

Post by larss »

Thanks a ton, this is exactly what I was looking for.
Last edited by larss on Tue May 19, 2009 5:52 pm, edited 1 time in total.
User avatar
plger
Forum Members
Forum Members
Posts: 196
Joined: Wed Oct 15, 2008 10:38 am

Re: Calling other modules from a method

Post by plger »

No problem.
You should mark the topic as [solved]...
Post Reply

Return to “Developers Discussion”