XF 1.5 Extending models results in "Cannot declare class, name is already in use" error

jlevers

New member
I'm pretty new to XF development...I'm working on an extension, and my controller extensions are working fine, but all my model extensions are resulting in a Cannot declare class XFCP_<class_name>, because the name is already in use error.

There aren't classes with the same names as my model extension classes anywhere else, so I'm not sure what would be causing the problem. Here's my Listener.php file:

PHP:
<?php

class AddOn_Listener
{
    public static function loadClassController($class, array &$extend) {
        if ($class == 'XenForo_ControllerPublic_Thread')
        {
            $extend[] = 'AddOn_ControllerPublic_Thread';
        }
    }

    public static function loadClassModel($class, array &$extend) {
        if ($class == 'XenForo_Model_Thread')
        {
            $extend[] = 'AddOn_Model_Thread';
        }
        else if ($class == 'XenForo_Model_Post')
        {
            $extend[] = 'AddOn_Model_Post';
        }
    }
}

I've created code event listeners in the admin as well, which use loadClassModel] for the model extensions and loadClassController] for the class extension.

My model extension class declarations look like class AddOn_Model_Thread extends XFCP_AddOn_Model_Thread {...}.

Any thoughts on what's going on here? Thanks!
 
Alright, I was able to fix this by adding hints to the event listeners, and rewriting my Listener.php file to look like this:

PHP:
<?php

class OPOnly_Listener
{
    public static function loadClassController($class, array &$extend)
    {
        $extend[] = 'OPOnly_ControllerPublic_Thread';
    }

    public static function loadThreadModel($class, array &$extend)
    {
        $extend[] = 'OPOnly_Model_Thread';
    }

    public static function loadPostModel($class, array &$extend)
    {
        $extend[] = 'OPOnly_Model_Post';

    }
}

However, from looking through other Listener.php files I was able to find online, I don't think this is the usual way of fixing this. I'd still be interested in hearing how this is usually dealt with. Thanks!
 
Top Bottom