[SOLVED] Calling Module functions from within a UDT

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
spcherub
Power Poster
Power Poster
Posts: 402
Joined: Fri Jun 06, 2008 5:54 pm

[SOLVED] Calling Module functions from within a UDT

Post by spcherub »

I would like to be able to call on functionality within modules from within a UDT. The CMS Cookbook has one example of how to call the AddNewArticle in the New module to post a new News article from the within the UDT.

I am wondering if there is a way to call other functions that are not necessarily designed as a part of the API. For instance I would like to be able to get all the data about a news article by passing a function an article ID. This functionality already exists within the News module (within the action.detail.php file), but because it is not encapsulated within a function call, I am not able to call on it. I suspect there is something to do with the DoAction call, but I am not clear on the syntax.

Any ideas of how I can do this?

I am trying to avoid writing code that reads data from the News tables when all the functionality I want is already available in the News module.

TIA
-S
Last edited by spcherub on Wed Sep 21, 2011 2:57 pm, edited 1 time in total.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: Calling Module functions from within a UDT

Post by calguy1000 »

You can call DoAction yourself.

The returnid would be your current page id.
The params would be a hash of the stuff you normally send on the module call.
The $id could be anything.

You would then have to DISREGARD the output of the DoActionc all (becase DoAction is usually expected to return rendered output), and extract the data you want from the various smarty variables.

$smarty->get_template_vars() will show you which smarty variables are available.
$something = $smarty->get_template_vars('something'); will extract that smarty variable into something you can use in php.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
spcherub
Power Poster
Power Poster
Posts: 402
Joined: Fri Jun 06, 2008 5:54 pm

Re: Calling Module functions from within a UDT

Post by spcherub »

Nevermind - found the syntax for the DoAction call...

$news_module->DoAction('detail', "", $params);

Thanks.
S
spcherub
Power Poster
Power Poster
Posts: 402
Joined: Fri Jun 06, 2008 5:54 pm

Re: [SOLVED] Calling Module functions from within a UDT

Post by spcherub »

@calguy: Thanks for the detailed explanation. In my case I was actually looking for the processed (template) output, so it actually works, but I can see how it can be more flexible to disregard the output and use the template cars instead. Any ideas how I can suppress the output of the DoAction call - do it have to do with output buffering?

TIA
-S
spcherub
Power Poster
Power Poster
Posts: 402
Joined: Fri Jun 06, 2008 5:54 pm

Re: [SOLVED] Calling Module functions from within a UDT

Post by spcherub »

Ok I should have done some reading before I posted the question. I found the following that should work for this situation:

Code: Select all

@ob_start();

                    $result = $news_module->DoAction($action, $id, $params, $returnid);
                    if ($result !== FALSE)
                    {
                        echo $result;
                    }
                    $modresult = @ob_get_contents();
                    @ob_end_clean();
Post Reply

Return to “Developers Discussion”