Newbe needs help with first 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
musicscore
Power Poster
Power Poster
Posts: 474
Joined: Wed Jan 25, 2006 11:53 am
Location: Netherlands

Newbe needs help with first module

Post by musicscore »

I'm trying to build my first simple module.
I managed to create the install and uninstall part.
After installing the module I file the database with 2 record.
But there is now output in my page

This is my code

Code: Select all


/* Your initial Class declaration. This file's name must be "[class's name].module.php", or, in this case,
   Catlist.module.php
*/ 
class Catlist extends CMSModule
{

    function GetName()
    {
        return 'Scim';
    }

    function GetFriendlyName()
    {
        return $this->Lang('friendlyname');
    }

    function GetVersion()
    {
        return '0.1';
    }
         
    function IsPluginModule()
    {
         return true;
    }
	
	// Install - Unstall Messages 
	function InstallPostMessage()
	{
		return $this->Lang('postinstall');
	}
	
	function UninstallPreMessage()
	{
		return $this->Lang('uninstall_confirm');
	}

	function UninstallPostMessage()
	{
		return $this->Lang('postuninstall');
	}
	
	function DoAction($action, $id, $params, $returnid=-1)
	{
		if ($action == 'default')
		{
			$db =& $this->GetDb();
			$sql = 'SELECT * FROM ' . cms_db_prefix().'module_scim_players';
			$dbresult =& $db->Execute($sql);
     
			$list = "Spelers<br /><br />\n";
			$list .= "<ul>\n";
			while ($dbresult && $row = $dbresult->FetchRow())
			{                    
				$list .= "<li><b>" . $row['voorletters'] . '</b><br />';
				
				$list .= $row['roepnaam'] . '<br />';
				$list .= $row['tussenvoegsel'] . '<br />';
				$list .= $row['achternaam'] . '<br />';
				$list .= "</li>\n";
			}
		$list .= "</ul>\n";
		$list .= "<br /><br />\n";
		}
	
	// assign to Smarty
	global $gCms;
	$this->smarty->assign('list', $list);
	/**
    *Insert: {cms_module module='Scim'}{$list}
    *in your page template
    *But there has to be a way for this to work without the {$list} tag...
    **/
	return;
	}
}
?>
I then enter the tag on my page. No error, but also no output.
What is going wrong. Please help me.
I tryed to use the manual on the documentation page of cmsmadesimple.org

Musicscore
Jos
Support Guru
Support Guru
Posts: 4019
Joined: Wed Sep 05, 2007 8:03 pm
Location: The Netherlands

Re: Newbe needs help with first module

Post by Jos »

Do you have a template for frontend display of your module?

In the default action goes the code:

Code: Select all

// Display template
echo $this->ProcessTemplateFromDatabase($template);


For this example to work, you need to have a template for your module in the database.

In that template you can display with {$list}

It's nicer to make $list an array and have a smarty foreach to loop throught the $list array, and add the html code there, in stead of in your php code

You may want to install the skeleton module for a nice example.
Post Reply

Return to “Developers Discussion”