1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Proper way to add functions to XenForo_Model_Import

Discussion in 'XenForo Development Discussions' started by Deek, Sep 9, 2011.

  1. Deek

    Deek Member

    I'm currently working on my own custom importer for Vanilla forums. I've created the listener for my class
    class TheCollectiveMind_Importer_Vanilla extends XenForo_Importer_Abstract
    and its going well so far but I need to make a custom methods that aren't in XenForo_Model_Import

    I want to be able to call these functions on my model declared by
    $model $this->_importModel
    then called in my TheCollectiveMind_Importer_Vanilla by
    What is the proper method of extending XenForo_Model_Import so I'm able to do this?

    For refrence here is the function I need to be able use.
    public function getUserNameByEmail($email)
        SELECT username
        FROM xf_user
        WHERE email = ?
  2. Mike

    Mike XenForo Developer Staff Member

    You can dynamically extend the model using the load_class_model event.
  3. ragtek

    ragtek Guest

  4. Deek

    Deek Member

    I created a listener for load_class_model event and here is the class I created
    class TheCollectiveMind_Listener_Importer_Vanilla
        public static function 
    loadClassModel($class, array &$extend)
    $class == 'XenForo_Model_Import')
    extend[] = 'TheCollectiveMind_Model_Import_Vanilla';
    extend[] = 'TheCollectiveMind_Model_Import';
    But then I get the error
    Fatal error: Call to undefined method TheCollectiveMind_Model_Import::getImporter() in <path>/library/XenForo/ControllerAdmin/Import.php on line 104
    The importer I created works fine but once I added extend[] = 'TheCollectiveMind_Model_Import'; that's when the problems happened.

    Is this the wrong way to simply add a function (or two) into the base Import Model?

Share This Page