How to create a admin module

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Locked
jst4fun

How to create a admin module

Post by jst4fun »

Hi,
I am new to cmsms and being a developer I am trying to learn the development of modules. I was able to find a decent tutorial at http://wiki.cmsmadesimple.org/index.php/User_Handbook/Developers_Guide/Module_Tutorial. The only problem is that the tutorial is not complete and I think it would only be complete after having the admin side development. I am trying to create a module which require data entry form from the admin side. So I am in search for a tutorial or documentation which would help me do the same. If anyone could point me to the right resources (or provide a brief explanation) on implementing the admin site it would be very helpful to me. Thank you.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: How to create a admin module

Post by calguy1000 »

The questions module is a good reference..... it's clean and easy to read.

Basically, everything in the admin is done, like in the frontend with 'actions'.  the default action for the frontend is 'default', and the default action in the admin is 'defaultadmin'.  you'll see files action.default.php and action.defaultadmin.php in the questions module.

After that, in the admin, the accepted standard is to setup your admin tabs (usually there's two or more) in action.defaultadmin.php, and to start creating your forms using the api's in lib/classes/  particularly lib/classes/class.module.inc.php.

The magic function is CreateFormStart($id,'destinationaction',$returnid,...)  this creates the and various hidden tags to allow the system to work.    when a submit button is pressed in your form see CreateInputSubmit(...) the destination action would be called.  The accepted standard (these days) is to capture that in action.destinationaction.php.  All of the parameters from the various form elements will be available in the $params array.

There's the quick 2 minute tutorial. 
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.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: How to create a admin module

Post by calguy1000 »

I just thought I'd add a quick and dirty example here (untested of course, but it's close) of a form.  This simple form has two buttons, and it's destination action is the same as the action that originates it.

in action.defaultadmin.php:

Code: Select all

<?php
if( isset($params['do_this']) )
   {
      die('do this was pressed');
   }
else if( isset($params['do_that']) )
   {
       die('do that was pressed');
   }
$smarty->assign('formstart', $this->CreateFormStart($id,'defaultadmin',$returnid));
$smarty->assign('formend',$this->CreateFormEnd());
$smarty->assign('button1',$this->CreateInputSubmit($id,'do_this',$this->Lang('do_this'));
$smarty->assign('button2',$this->CreateInputSubmit($id,'do_that',$this->Lang('do_that'));
echo $this->ProcessTemplate('dummy_form.tpl');
?>
in templates/dummy_form.tpl

Code: Select all

{$formstart}{$button1}{$button2}{$formend}

in lang/en_US.php

Code: Select all

<?php
$lang['do_this'] = 'Do This Prompt';
$lang['do_that'] = 'Do That Prompt';
?>
Of course this doesn't do security checks, doesn't do parameter cleaning, doesn't use admin tabs, the database, preferences, or any of the other things that go into writing a good module, it's a simple form, but it should work.
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.
jst4fun

Re: How to create a admin module

Post by jst4fun »

Thank you very much calguy. I will try it out and will let you know the results. One more doubt what is the difference between a plugin and module in CMSMS?
BTW I would like to request the doc team to update the developer documentation (like the module development)as it would be very helpful to new developers like me to get started. Thanks 
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: How to create a admin module

Post by calguy1000 »

A plugin is a single file smarty plugin like {contact_form} or {cms_selflink} they can provide a form, and do various things, but the big differences are:

a) Plugins don't have an admin interface
b) Plugins don't have a translation mechanism
c) Plugins don't have a preferences mechanism
d) Plugins don't have an install/uninstall mechanism and therefore don't usually store things in the database
    or in files

There are more, but I can't think of them right now.
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.
jst4fun

Re: How to create a admin module

Post by jst4fun »

Calguy thanks once again. Your posts were really helpful.  :)
Locked

Return to “CMSMS Core”