I'm creating a new module for paid membership, called "Membership". This is my first module in PN and I'm basing it on the Example module supplied with PN0.750-RC3. I'm following the Module Development Guide for what it's worth and I'll add comments to that as I come across useful stuff. At the moment I have a problem.
I have created my pntables.php with the Membership_pntables function defining my tables.
I have created my pninit.php with the code to create the tables using the Membership_pninit function.
I have updated the pnversion.php file and when I regenerate the Module list under Admin, everything is shown as I expect it to.
When I initialise the module, it says it's worked. However, the tables aren't created. In fact if I remove the pninit.php file and initialise the module it still says it's initialised okay. Same if I remove the pntables.php file. I have a feeling it's not calling the right script.
What am I doing wrong :?: It doesn't bode well for the rest of the development does it?
P.S. A forum for help in creating modules would be really useful :)
Watch
GitHub Core
Show your support for Zikula! Sign up at Github account and watch the Core project!
GitHub Modules
- mazdev responded to »Zikula 1.3.3 - Selecting a category in Pages not working« 24. May
- nestormateo responded to »Fillters in Clip« 24. May
- damon responded to »Can the Updated Version Check be Turned Off (Z 1.3)« 24. May
- frw responded to »Bug in the SMTP mail transfer protocol - Port 25 - Zikula 1.2.9« 22. May
- mdee responded to »Short URL questions« 22. May
- mesteele101 responded to »Problem in Database Connection« 21. May
- Herr.Vorragend responded to »Clip Documentation and Doubt« 19. May
Zikula Blog
- Anatomy of Open Source Projects on Mar 07
- Continuous Review on Mar 01
- Not Invented Here on Feb 24
- How to Contribute Your Code at Github on Jan 13
- 10 Steps to Coding-Nirvana: Tips for Successful Module Writing on Nov 12
- Submitting Bug Report Tickets That Get Results on Aug 17
- Cozi Tricks #1: Syntax Highlighting on Aug 07
Login
A push in the right direction for my first module please
-
- Rank: Softmore
- Registered: May 25, 2004
- Last visit: Oct 21, 2009
- Posts: 192
-
- Rank: Team Member
- Registered: Mar 18, 2002
- Last visit: Oct 21, 2009
- Posts: 6606
A couple of tips and tricks.
Firstly ensure there aren't any syntax errors in your pntables/pninit files. The quickest way to check this is to call the two files directly in a browser i.e. http://www.yoursite.com/module/yourmod/pninit.php. Assuming you've display_errors on in your PHP configuration (check this via php.ini or a phpinfo report) then any syntax errors will be displayed.
Secondly check the SQL is valid. Just prior to excuting the SQL ($dbconn->execute) add the following code
This will echo the generated SQL and halt the script. Copy and paste the resultant SQL in phpMyAdmin and see if this gives you anything useful.
-Mark
--
Visit My homepage and Zikula themes. -
- Rank: Softmore
- Registered: May 25, 2004
- Last visit: Oct 21, 2009
- Posts: 192
Mark,
Excellent. I had a couple of spare brackets lurking around in my pninit.php. Still not working, but I'm on the right track. Strange that it says it has initialised okay though, when the code is pants. A bug perhaps?
Ta meester.
UPD. All sorted now. I'm sure this won't be the last post about this module. I'm updating the MDG with helpful tips as I go. -
- Rank: Team Member
- Registered: Mar 18, 2002
- Last visit: Oct 21, 2009
- Posts: 6606
A bug - well not really..... The way the PHP lanugage handles includes doesn't really give too much scope for any error hanldling. The include function doesn't return a result than can be checked. You have to go the whole hog and have a full error trapping system - this is in the works though....
So at the moment an include failing due to a syntax error in the included file is the same as the include failing due to no file being present. And if there is no pninit file present then we assume there's no init script needed for this module (rather than force a dummy script) and thus the module should initialise fine....
Please send me any updated docs for the MDG - also bear in mind that not all of the MDG has been implemented as yet (hence PN is at 0.7x....). The MDG will need a good update for the .8x release.
-Mark
--
Visit My homepage and Zikula themes. -
- Rank: Softmore
- Registered: May 25, 2004
- Last visit: Oct 21, 2009
- Posts: 192
Okay, understand that.
I'm just adding comments to the MDG as I go, rather than formalising any documentation. Hopefully that'll help people developing modules now and can be used in any future changes to the MDG. -
**unknown user**
- Rank: Helper
- Registered: Mar 16, 2002
- Last visit: Oct 21, 2009
- Posts: 676
Mark,
Can't the system use something like
Code
$return = include($file);
and check the return? The documentation indicates this is possible, and that by default the return is 1 on success (true).
Martin -
- Rank: Team Member
- Registered: Mar 18, 2002
- Last visit: Oct 21, 2009
- Posts: 6606
Martin,
Your right.... i'd missed that in the docs. Every application i've used (PN included) doesn't use the return value from an include. I'll test this and add it to .8x (and .7x depending on when I get to it).
Thanks for pointing that out.
-Mark
--
Visit My homepage and Zikula themes. -
**unknown user**
- Rank: Helper
- Registered: Mar 16, 2002
- Last visit: Oct 21, 2009
- Posts: 676
No prob. Glad I can teach an old dog a new trick (hope that doesn't sound like an insult :) )
Even without it, if you need to initialise a module, surely the init function has to exist, and similarly with Updating/Deleting, so if function_exists should be able to at least report failure if it doesn't. Better than it reporting success when nothing has happened. -
**unknown user**
- Rank: Helper
- Registered: Mar 16, 2002
- Last visit: Oct 21, 2009
- Posts: 676
I just tested this in modules/Modules/pnadminapi.php
Code
// Module initialisation function
$osdir = pnVarPrepForOS($modinfo['directory']);
$success=@include("modules/$osdir/pninit.php");
if ($success==false) {
pnSessionSetVar('errormsg', _MODINITFAILED);
return false;
}
@include("modules/$osdir/pnlang/" . pnVarPrepForOS(pnUserGetLang()) . "/init.php");
$func = $modinfo['name'] . '_init';
if (function_exists($func)) {
if ($func() != true) {
return false;
}
} else {
pnSessionSetVar('errormsg', _MODINITFAILED2);
return false;
}
and added this to the language file modules/Modules/lang/eng/admin.php
Code
Now it warns me that the initialisation failed and why. -
- Rank: Team Member
- Registered: Mar 18, 2002
- Last visit: Oct 21, 2009
- Posts: 6606
msandersen
Even without it, if you need to initialise a module, surely the init function has to exist, and similarly with Updating/Deleting, so if function_exists should be able to at least report failure if it doesn't. Better than it reporting success when nothing has happened.
Well that was the problem... A simple module may not need to create any tables, set any module vars, register any hooks etc. so PN has never required a init script - a look at the exiting codebase confirms this. So it's not as simple as a function_exists check.
But since we can check for a successful include there's a simple solution. I'd never got that far down the include documentation. Thanks for the patch - i'll include this in the codebase this weeknd.
'old dog' - ouch!.... I'm only 31..... ;)
-Mark
--
Visit My homepage and Zikula themes. -
**unknown user**
- Rank: Helper
- Registered: Mar 16, 2002
- Last visit: Oct 21, 2009
- Posts: 676
"old dog" relatively speaking! In terms of PN developers, I expect you are! (at least since the split). You are 3 years younger than me, so what does that make me? In terms of programming, though, I'm an amateur, I just play around a bit for fun.
You could make it a requirement to at least have the function for New-type modules, even if it just returns true; a module like PostJump virtually doesn't do anything in initialising (well, it sets one variable), but it has the function.
Or just post a warning that it was initialised in absence of the init file/function. That would suffice for developers, too.
Or maybe just have the feature for a developer Debug mode in Settings. -
- Rank: Softmore
- Registered: May 25, 2004
- Last visit: Oct 21, 2009
- Posts: 192
How far have you got down the file_exists function you young whipper snappers?
- Moderated by:
- Support
