Callback class::method is invalid -> Error while createing new addon

TheBigK

Well-known member
I'm following furrman's tutorial:- https://xenforo.com/community/resources/how-to-read-and-write-into-the-database-with-a-page.328/

I've created file/folder structure as follows:-

library / SimpleText / Installer.php

Installer.php code:-
PHP:
<?php

class SimpleText_Installer
{
    //Creating required tables in the database

    // $table = array('createQuery', 'dropQuery')

    protected static $table = array(
        'createQuery' => 'CREATE TABLE IF NOT EXISTS `xf_simple_text` (
                `simple_id` INT( 10 ) NOT NULL AUTO_INCREMENT,
                `simple_text` VARCHAR ( 200 ),
                `simple_date` INT( 10 ) UNSIGNED,
                PRIMARY KEY (`simple_id`)
                )
            ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci;',
        'dropQuery' => 'DROP TABLE IF EXISTS `xf_simple_text`'
    );

    public static function install()
    {
        $db = XenForo_Application::get('db');
        $db->query(self::$table['createQuery']);
    }

    public static function uninstall()
    {
        $db = XenForo_Application::get('db');
        $db->query(self::$table['dropQuery']);
    }

}

I saved the file, then went to admin control panel and created a new addon with following Information:-

Add-on ID: SimpleTextAddon
Title: Simple Text Add On
Version String: 1.0
Version ID: 1
Installation Code: SimpleText_Installer :: install
Uninstallation Code: SimpleText_Installer::uninstall

When I click 'Save Addon', I'm getting an error in overlay that says -

Please correct the following errors:
  • Callback SimpleText_Installer::install is invalid (Invalid Class).
  • Callback SimpleText_Installer::uninstall is invalid (Invalid Class).

I'm unable to figure out why is the system not accepting my class::method. Can someone tell me what's missing or wrong?
 
Everything you have typed above looks correct, so my only assumption is that something must be typed different to how it it above.

e.g are you sure the folder where the PHP is is actually called SimpleText? Rather than simpletext? Or Simpletext? Are you sure it's spelt correctly?

Same goes with the file name. It will be case sensitive.
 
Bang on! My 'SimpleText' folder was at the same level as 'library'. Damn, I gotta get used to this new IDE. I moved SimpleText under library and it worked.

Should have be more careful.
 
Back
Top Bottom