Zikula: A Flexible Open Source Content Management System
home | forum | contact us

Dizkus

Bottom
initialization not working
  • Posted: 22.03.2005, 11:06
     
    davepan
    rank:
    Freshman Freshman
    registered:
     April 2002
    Status:
    offline
    last visit:
    19.12.05
    Posts:
    15
    OK. I'm just getting started with trying to build a fairly simple module that will send out an email invitation for events to a limited group of individuals that the user can specify.

    My pnversion.php file looks like this:

    $modversion['name'] = 'pnEvite';
    $modversion['version'] = '1.00';
    $modversion['description'] = 'Sends out an electronic invitation to an event';
    $modversion['credits'] = 'pndocs/credits.txt';
    $modversion['help'] = 'pndocs/help.txt';
    $modversion['changelog'] = 'pndocs/changelog.txt';
    $modversion['license'] = 'pndocs/license.txt';
    $modversion['coding'] = 'pndocs/coding.txt';
    $modversion['official'] = 0;
    $modversion['author'] = 'David A. Pancost';
    $modversion['contact'] = 'dave@strategicwebconcepts.com';
    $modversion['admin'] = 1;
    $modversion['securityschema'] = array();

    I copied and modified what I found in the Template module's pninit.php (with the exception of the upgrade function). Here's what that looks like:

    function pnEvite_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
    $dbconn =& pnDBGetConn(true);
    $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
    $pnEviteTable = $pntable['pnEvite'];
    $pnEviteColumn =& pntable['pnEvite_column'];

    // 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 $pnEviteTable (
    $pnEviteColumn[EventDate] date,
    $pnEviteColumn[EventMessage] text ,
    PRIMARY KEY(pn_EventDate))";
    $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) {
    return false;
    }

    function pnEvite_delete()
    {
    // 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
    $dbconn =& pnDBGetConn(true);
    $pntable =& pnDBGetTables();

    // Drop the table - for such a simple command the advantages of separating
    // out the SQL statement from the Execute() command are minimal, but as
    // this has been done elsewhere it makes sense to stick to a single method
    $SQL = "DROP TABLE $pntable[pnEvite]";
    $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) {
    // Report failed deletion attempt
    return false;
    }

    // Delete any module variables
    pnModDelVar('pn_Evite', 'EDate');
    pnModDelVar('pn_Evite', 'EMessage');

    // Deletion successful
    return true;
    }

    Now here's my question. When I regenerate my modules list, the pnEvite module shows up in my list and initialize is the first option under Actions. When, however, I click on Initialize, my browser goes blank and nothing happens. No database is created and my browser simply becomes a BLANK SCREEN. Can somebody help me figure out what I've done wrong and get my Initialize function working? Or at least point me in the right direction to figure out what I can do to find out why things aren't working?

    Thanks.
  • Posted: 22.03.2005, 16:15
     
    Landseer
    rank:
    Developer Developer
    registered:
     January 2003
    Status:
    offline
    last visit:
    27.11.08
    Posts:
    851
    Debugging the init function is not easy because it does not throw any errors.

    Try to add some echo "i am here now"; statements and check the $SQL (main source of problems).

    --
    "He is not dangerous, he just wants to play...."
  • Posted: 22.03.2005, 17:02
     
    jediping
    rank:
    Helper Helper
    registered:
     November 2004
    Status:
    offline
    last visit:
    12.03.07
    Posts:
    387
    Is that all your code for the init function? Because it looks like the initialization function isn't closed before the delete function begins.

    Otherwise, a good way to check initialization is to print the SQL statement and then say "die;" and then examine the SQL for errors. Of as Landseer said, some basic, "Hello, world." echos and then die.
  • Posted: 22.03.2005, 21:33
     
    davepan
    rank:
    Freshman Freshman
    registered:
     April 2002
    Status:
    offline
    last visit:
    19.12.05
    Posts:
    15
    Thanks for the replies. I've tried to implement the suggestions you all made but I'm still getting nothing. I can't get any of the echo statements to show up...just a BLANK SCREEN.

    I don't know if this will help, but I'm using my local machine as a development environment, and this is what I get when I click on the initialize link:

    http://localhost/~davep/postnuke/html/index.php?module=Modules&
    type=admin&func=initialise&id=50&
    authid=f8ac7fc2cca5df987d01a5b84b657430

    Jediping, when I cut and pasted my pninit.php functions I apparently didn't copy the closing bracket to the initialize function. I did, however check to see if the function was closed before the delete function and it is.

    Any other suggestions?

    Thanks again.

    Dave
  • Posted: 22.03.2005, 22:03
     
    ctimmer
    rank:
    Helper Helper
    registered:
     February 2003
    Status:
    offline
    last visit:
    11.06.08
    Posts:
    226
    Try this (originally suggested by Markwest):
    http://localhost/~davep/postnuke/html/modules/MYMODDIR/pninit.php

    If the syntax is correct you should only see a BLANK SCREEN.
  • Posted: 22.03.2005, 23:03
     
    davepan
    rank:
    Freshman Freshman
    registered:
     April 2002
    Status:
    offline
    last visit:
    19.12.05
    Posts:
    15
    Thanks for all the suggestions and help. I've got it working now. Here's what the problem was (sheesh! Do I feel dumb!):

    $pntable =& pnDBGetTables();

    Should be

    $pntable = &$pnDBGetTables();

    Sometimes ya just gotta stare at something 'till you get it. icon_redface

    Thanks again. I'm sure I'll be back. :)

    Dave

Extensions Moderation

Main Menu

Extensions Database

Documentation

Development

Login

Donate to Zikula