Login to download the latest version of Mint and your favorite Pepper, purchase additional licenses, or post in the Forum. Don't have an account? Create one!

In Partnership with Media Temple

Mint Forum

General API questions

Nial
Pepper Developer
Posted on Jul 14, '08 at 02:40 pm

I have two questions regarding the Mint API. I’m developing a ‘silent’ application (which doesn’t render a pane). The application simple updates a database table whenever it’s loaded.

1) I’ve placed the database update code within the onPepperLoad() method. However, whenever the site is reloaded, the database is updated six times (this is a consistent number). Is there something I should be aware about with the onPepperLoad method, or is this likely down to problems in my code?

2) I’m trying to setup and update a manifest, like so:

var $manifest = array ( 'hint' => array ( 'last_updated' => "INT(11) NOT NULL" ) );

However, looking at other Peppers, it seems that a manifest is only updated onRecord()? Is there any easy way to update a manifest if my Pepper doesn’t utilize any javascript?

Nial
Pepper Developer
Posted on Jul 14, '08 at 02:51 pm

With regards to my question number 1): Having placed a quick echo in onPepperLoad, I see that it’s being called once for each of my additional Peppers. Is there a way to tell whether that particular call is for your Pepper, or is it easier to just add an alreadyRun boolean, or something?

Shaun Inman
Mint/Pepper Developer
Posted on Jul 14, '08 at 06:15 pm

The manifest property of a Pepper is never updated. The manifest stores a simplified description of a database table. You should not be manipulating your manifest in any way.

the database is updated six times

It sounds like your modifying the parent Pepper class (found in app/libs/pepper.php) rather than your own specific Pepper (which should go in pepper/yourdevelopertoken/peppername/class.php) that inherits from the Pepper class. I would recommend the Intro to Pepper Development series of articles I wrote a while back to understand how to use the API.

Nial
Pepper Developer
Posted on Jul 14, '08 at 07:18 pm

Shaun, I’m manipulating my own class, as per the suggestions in your Intro to Pepper Development. Here’s a snippet of my code:

`if (!defined(‘MINT’)) { header(‘Location:/’); };

$installPepper = “PA_Hint”;

class PA_Hint extends Pepper {

var $version    = 1; // Displays as 0.01
var $collectedData = array();
var $info       = array
(
    'pepperName'    => 'Hint',
    'pepperUrl'     => 'url',
    'pepperDesc'    => 'Description.',
    'developerName' => 'Nial Giacomelli',
    'developerUrl'  => 'url'
);
var $manifest = array
(
    'hint' => array
    (
        'last_updated' => "INT(11) NOT NULL"
    )
);
var $prefs      = array
(
'enabled'   => 1
);
function isCompatible() {
    if ($this->Mint->version >= 120)
    {
        return array
        (
            'isCompatible'  => true
        );
    }
    else
    {
        return array
        (
            'isCompatible'  => false,
            'explanation'   => '<p>This Pepper is only compatible with Mint 1.2 and higher.</p>'
    );
    }
}
function onPepperLoad() {`

Yet, this is still triggered six times, when each Pepper is loaded.

I’m still confused with regards to the manifest. If my Pepper wishes to store a variable in the database, should I manually create a table + value?

Nial
Pepper Developer
Posted on Jul 14, '08 at 07:58 pm

Here’s a cut-down version of the class: http://pastebin.com/m7c4a125d

Nial
Pepper Developer
Posted on Jul 15, '08 at 06:02 am

I’ve also downloaded a few other Pepper’s and edited them to include an onPepperLoad method that echo’s a string. These all seem to be called with each Pepper load.

I’m using a vanilla Mint installation (bar a few Pepper’s - Backup/Result, User Agent 007).

Shaun Inman
Mint/Pepper Developer
Posted on Jul 15, '08 at 10:28 am

You are probably seeing multiple instances of that echo statement because you have “Stagger Pane Loading” enabled in your Mint Preferences.

With this enabled, loading the Mint url loads just the pane containers initially with subsequent requests being made to fetch the individual pane content. It’s not that your code is being called six times when Mint is loaded, it’s the Mint is being loaded six times and your code is being called once for each of those six Mint instances.

Shaun Inman
Mint/Pepper Developer
Posted on Jul 15, '08 at 10:30 am

onPepperLoad() is never the place to perform code that updates the Mint database. You should be using onRecord(), onJavaScript() or onDisplay() for these purposes.

Nial
Pepper Developer
Posted on Jul 15, '08 at 12:20 pm

Shaun, thanks for the reply! However, I’m having trouble getting any code to execute in the onRecord(), onJavaScript() and onDisplay() methods. I assume onDisplay is only called when you declare a pane?

Similarly, my Pepper doesn’t have a script.js. I tried creating a basic JS file:

if (!Mint.PA) { Mint.PA = new Object(); } Mint.PA.Hint = {

onsave  : function() { return ''; }

};

Sadly, no luck!

Shaun Inman
Mint/Pepper Developer
Posted on Jul 15, '08 at 02:27 pm

Try defining an onAfterDisplay() method. That should be called regardless of whether your Pepper displays a pane or not.

You must be logged in to reply. Login above or create an account