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

Please Enter a Valid callback method when saving code even listener?

Discussion in 'XenForo Development Discussions' started by Liam W, Apr 20, 2013.

  1. Liam W

    Liam W Well-Known Member

    I'm trying to make my first xenForo mod, and am having trouble :(

    I have tried making a code event listener, I have the file (I followed the tutorial), and I named the class and the function, however when I enter those details into the code event listener thing it gives me an error when I try and save it.

    This is my LoadClassController.php file (saved in <forum root>/Library/CPFirewall/Listener):

            public static function 
    loadClassListener($class, &$extend)
                    if (
    $class == 'XenForo_ControllerAdmin_Login')
    $extend[] = 'CPFirewall_ControllerAdmin_EmailLogin';
    When I enter CPFirewall_Listener_LoadClassController :: loadClassListener in the code event listener create page, it gives me an error when I save, saying I have to enter a valid callback method.

    Any help? What I am doing wrong? I am very new to xenForo, so yeah ;)
  2. borbole

    borbole Well-Known Member

    Change the class name to this:

    class CPFirewall_Listener_LoadClassListener

    That part should reflect the name of your listener file name.
  3. Rigel Kentaurus

    Rigel Kentaurus Well-Known Member

    Usually this means "could not find the file". 90% of my times my problem is wrong case (uppercase-lowercase, etc), or the file is not in the correct place.

    Check that you have

    1) <XENFORO_ROOT>/library/CPFirewall/Listener
    2) File is named "LoadClassController.php"
    3) Class is named CPFirewall_Listener_LoadClassController

    4) You enter in the add-on section CPFirewall_Listener_LoadClassController :: loadClassListener

    The fact that you typed Library uppercase was already making me nervous :)
  4. Liam W

    Liam W Well-Known Member

    Whoops, made a mistake - the file is called LoadClassController.php
  5. Liam W

    Liam W Well-Known Member

    All of those points have been validated, and I'm still getting the error :(
  6. borbole

    borbole Well-Known Member

    Double check them again because either the path or the file/class name/s is not correct.
  7. tyteen4a03

    tyteen4a03 Well-Known Member

    Note that in Windows the file name is not case-sensitive while in UNIX it is.
  8. Filetrip

    Filetrip Member

    You should use <?php opening tags instead of <?
    This shouldn't be the problem if the shorthand is enabled on your server, but it can be disabled on other servers (if you want to release your addon)
    Rigel Kentaurus, borbole and Liam W like this.
  9. Liam W

    Liam W Well-Known Member

    Didn't notice I was using the short version!

    And they were disabled in XAMPP it would seem! All working now, damn I could kick myself ;)
  10. borbole

    borbole Well-Known Member

    Good catch there.

Share This Page