OK, I'm sure this has been covered somewhere but I just CAN NOT find it and I'm at my wit's end.
I'm creating a module for a gaming organization that I run and I need to be able to add/manage/display different online games. I thought this would be a simple enough concept for my first module.
I followed the MDG and I'm in section 7.4 or 7.5 depending on how you look at it.
I created my inistialisation files (pninit.php) the way I should and the query I have added will create the table if I run it in a SQL tool. So I know the query works.
HOWEVER - function my_module_init() doesn't seem to ever get run...
The module is added to the module list successfully and I can even go as far as to activate it and have it show up in the administration section, but the tables are never created and nothing I put inside that function ever gets run (I tried printing some output, etc).
I'm sure I'm missing something obvious, but for the life of me I don't know what it is.
mySQL, Apache, PHP, PN - all the latest/greatest versions directly from the distributors.
Any help will be GREATLY appreciated.
Thank in advance!
Watch
GitHub Core
Show your support for Zikula! Sign up at Github account and watch the Core project!
GitHub Modules
- craigh responded to »Using PageUtil::addVar() to load script code« 03:29 PM
- michiel responded to »password problem« 10:01 AM
- mazdev responded to »Hide "Register new account" and change template to 3 col« 07:50 AM
- mesteele101 created topic »Zikula 1.3.3 - Site Search 1.5.2 - Unable to turn off plug-ins« 07:48 AM
- mesteele101 responded to »ERR (3): E_USER_ERROR: Smarty error: [in pagesvar:pagesitem2en line XXX]…« 25. May
- mazdev responded to »Pages 2.5.0 and updating - Page not found« 25. May
- mesteele101 responded to »Zikula 1.3.3 - Selecting a category in Pages not working« 25. 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
New/Custom Mod Not Running When Initialising
-
- Rank: Team Member
- Registered: Mar 18, 2002
- Last visit: Oct 21, 2009
- Posts: 6606
-
**unknown user**
- Rank: Registered User
- Registered: Mar 16, 2002
- Last visit: Apr 09, 2003
- Posts: 5
Here's the init function that doesn't seem to be working, or for that matter getting called.
Thanks a ton for your quick response...
Code
/**
* initialise the lag_games module
* This function is only ever called once during the lifetime of a particular
* module instance
*/
function lag_games_init()
{
// Get datbase setup - note that both pnDBGetConn() and pnDBGetTables()
// return arrays but we handle them differently. For pnDBGetConn()
// we currently just want the first item, which is the official
// database handle. For pnDBGetTables() we want to keep the entire
// tables array together for easy reference later on
list($dbconn) = pnDBGetConn();
$pntable = pnDBGetTables();
// It's good practice to name the table and column definitions you
// are getting - $table and $column don't cut it in more complex
// modules
$lag_games_table = $pntable['lag_games'];
// Create the table - the formatting here is not mandatory, but it does
// make the SQL statement relatively easy to read. Also, separating out
// the SQL statement from the Execute() command allows for simpler
// debug operation if it is ever needed
$sql = "CREATE TABLE $lag_games_table {
lag_gameid int(10) NOT NULL auto_increment,
lag_gamename varchar(100) NOT NULL default '',
lag_gamedescription text NOT NULL default '',
lag_gameimage varchar(100) NOT NULL default '',
lag_gamelink varchar(100) NOT NULL default '',
PRIMARY KEY(lag_gameid))";
$dbconn->Execute($sql);
)
// Check for an error with the database code, and if so set an
// appropriate error message and return
if ($dbconn->ErrorNo() != 0) {
pnSessionSetVar('errormsg', _CREATETABLEFAILED);
return false;
}
// insert default game
$gameid = $dbconn->GenID($lag_games_table);
$sql = "INSERT INTO $lag_games_table (lag_gameid, lag_gamename, lag_gamedescription, lag_gameimage, lag_gamelink)
VALUES($gameid,'Default','Default Game','image.gif','http://www.google.com')";
$dbconn->Execute($sql);
if ($dbconn->ErrorNo() != 0) {
pnSessionSetVar('errormsg', $dbconn->ErrorMsg());
return false;
}
// Set up an initial value for a module variable. Note that all module
// variables should be initialised with some value in this way rather
// than just left blank, this helps the user-side code and means that
// there doesn't need to be a check to see if the variable is set in
// the rest of the code as it always will be
// pnModSetVar('LaG_Games', 'bold', 0);
// pnModSetVar('LaG_Games', 'itemsperpage', 10);
// Initialisation successful
return true;
} -
- Rank: Team Member
- Registered: Mar 18, 2002
- Last visit: Oct 21, 2009
- Posts: 6606
I've given the code a quick look over can have spotted one potential problem
Code
....
$sql = "CREATE TABLE $lag_games_table {
.....
should read
Code
...
$sql = "CREATE TABLE $lag_games_table (
....
Note round bracket rather than a brace.
If this doesn't take care of the problem then if you zip the existing code up and let me know where I can download it i'll go through the code on one of my test installs.
-Mark -
**unknown user**
- Rank: Registered User
- Registered: Mar 16, 2002
- Last visit: Apr 09, 2003
- Posts: 5
Again, thanks for your response but that didn't seem to take care of the issue. That syntax error was actually left over from me trying to cause SQL errors to be generated so I could prove to myself that the code was being run. No such luck, I still got "Module initialised" as my message.
You can take a look at the entire module (note that I've only gotten as far as section 7.4-7.5 in the guide so I've only done the initialisation steps in the code you'll see) here: http://files.lividandgifted.com/users/S3VYN/LaG_Games.zip -
- Rank: Team Member
- Registered: Mar 18, 2002
- Last visit: Oct 21, 2009
- Posts: 6606
Donnie,
I've isolated the problem for you. The problem is a missing comma in the pntables array definition in pntables.php.
I've corrected this and updated the SQL create to use the pntables column as per the MDG.
New file can be found at http://www.markwest.…oads/LaG_Games.zip/. Let me know when you've grabbed the updated copy so I can remove it.
Good luck with the module.
-Mark -
**unknown user**
- Rank: Registered User
- Registered: Mar 16, 2002
- Last visit: Apr 09, 2003
- Posts: 5
Awesome, thanks so much Mark. I got the file and it seems to fix everything as advertised.
With this kind of service this may be a community I can sink my teeth into, a credit to open source development. :) -
- Rank: Team Member
- Registered: Mar 18, 2002
- Last visit: Oct 21, 2009
- Posts: 6606
S3VYN
Awesome, thanks so much Mark. I got the file and it seems to fix everything as advertised.
With this kind of service this may be a community I can sink my teeth into, a credit to open source development. :)
I'm always willing to try and help a developer get started. I was in the same position myself a while ago beginning my first module using the then new MDG and API standards.
-Mark
- Moderated by:
- Support
Users on-line
- 0 users
This list is based on users active over the last 60 minutes.
