Help writing a module

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
styson

Help writing a module

Post by styson »

Greetings,

I'm struggling at getting my module do pretty much anything.  I've followed the module howto, looked at the skeleton module and looked at several existing modules.  I understand the pieces needed to create the module and I've created a module that installs/uninstalls without errors but I cannot get it to do anything beyond that, even display a simple hello world message.  The pieces of CMSms are just not fitting together for me so I'm looking for a bit of help.  I am not an OO programmer by trade nor education and I'm a PHP novice.  However, I have extensive experience with ASP/VB COM as well as a few now dead Mainframe programming languages.  So I'm not completely clueless but I'm struggling nonetheless. 

Here is what I want my module to do:

This module will be processing a form post and using the frontenduser module to autologon a user.
  • Check to see if the page was called by for post.  I can do this with standard php, is there anything beyond that for CMSms. Display a happy user oriented error message if the page was access directly without a post
  • Extract the form fields into local variables
  • using one of the form fields, call the frontenduser module and log the user on
  • If the login failed (no account) then call the frontenduser module and create an account.  Then Call the frontenduser module and log the user on
  • Extract a session variable that holds a URL (CMSms page) and redirect the logged in user to that page
  • for debug purposes, I'd like to be able to echo things back to the page
  • no database tables are needed for this module nor any admin functions
In a nutshell that is it.  We are using the FEU and CustomContent modules to secure content (no personal or sensitive data is being secured) for users but those user accounts are maintained in another system. The FEU pages and functions wont be exposed on any other pages, just through this page.

Anyone care to help me out? 
styson

Re: Help writing a module

Post by styson »

  • Well, I solved one problem and that was how to get information to display on my page. 

    Things I did to get this to work: 

    Created a template directory and added the file plugin.tpl  Contents of this file is:[/li]

Code: Select all

<h3>{$mytext}</h3>
Then in my modulename.module.php file I created the  DoAction function:

Code: Select all

   function DoAction($action, $id, $params, $returnid=-1)
    {
       global $gCms;   
       if ($action == 'default')
       {     	    	
        $this->smarty->assign('mytext', 'Howdy Doody');
    	echo $this->ProcessTemplate('plugin.tpl'); 
        return;
       }
      else
      {
 	$this->smarty->assign('mytext', 'FOOBAR');
    	echo $this->ProcessTemplate('plugin.tpl');     	
        return;
      }
} 
Not sure if the global command is necessary or not?

Lastly, I had to include the function IsPuginModule:

Code: Select all

   	function IsPluginModule()
	{
		return true;
	}
This last part was key.  It tells CMSms that this module can be included in a page using the following syntax:

Code: Select all

{cms_module module=mymodulename}
When I create a page and include the module then view the page, it displays the text Howdy Doody formated with the H3 html tags.  If I were to pass the mdoule a different action, it would display the text FOOAR.   

A small step forward.
Post Reply

Return to “Developers Discussion”