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

What am I doing wrong?

Discussion in 'XenForo Development Discussions' started by MOZ, Jul 18, 2012.

  1. MOZ

    MOZ Well-Known Member

    I'm starting work on a new add-on, and while defining the event listener, I get the following error: "Please enter a valid callback method."

    Here is my directory structure:
    [​IMG]


    Contents of LoadClassController.php:
    PHP:
    <?php
     
    class SortMem_Listener_LoadClassController
    {
        public static function 
    loadClassListener($class, &$extend)
        {
            if (
    $class == 'XenForo_ControllerPublic_Member')
            {
                
    $extend[] = 'SortMem_ControllerPublic_Member';
            }
        }
    }

    Contents of Member.php:
    PHP:
    <?php
     
    class SortMem_ControllerPublic_Member extends XFCP_SortMem_ControllerPublic_Member
    {
     
        public function 
    actionIndex()
        {
     
        }
     
    }

    Code Event Listener Editor:
    Liston to event: load_class_controller
    Execute Callback: SortMem_Listener_LoadClassController::loadClassListener
     
  2. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Everything looks correct. Maybe the function signature? The documentation says:

    $class, array &$extend
     
  3. MOZ

    MOZ Well-Known Member

    Tried, still nothing :(
     
  4. MOZ

    MOZ Well-Known Member

    Now getting these errors:

    Warning: Unexpected character in input: ' in /home/raidcom/public_html/community/library/SortMem/Listener/LoadClassController.php on line 1

    Parse error: syntax error, unexpected T_CLASS in /home/raidcom/public_html/community/library/SortMem/Listener/LoadClassController.php on line 2
     
  5. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    I don't see any typos in the paths, file names, or class names. Make sure LoadClassController.php is saved before you create the listener.
     
  6. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    What text program? Make sure the files are saved in plain text.
     
  7. MOZ

    MOZ Well-Known Member

    Please help, can you try on the above and see if it works?
     
  8. MOZ

    MOZ Well-Known Member

    notepad++
     
  9. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    There are no syntax errors in the code you posted. If not a bad save or incorrect formatting then another possibility would be a misbehaving cache in PHP.
     
  10. MOZ

    MOZ Well-Known Member

    How would I go about correcting that?
     
  11. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Are you sure you are working with the correct installation of XF? I see both Windows and Linux paths in your posts.
     
  12. MOZ

    MOZ Well-Known Member

    Weird isue, it was a bad save, I wrote the code again and this time both the files were half the size. :confused:
     
  13. MOZ

    MOZ Well-Known Member

    First was on my test installation, whereas the second one is from my actual installation
     
  14. MOZ

    MOZ Well-Known Member

    Thanks for the assist Jake! :)
     
  15. MOZ

    MOZ Well-Known Member

    Hey Jake, I know this isn't the best place to ask this, however, how would I get variables from the XenForo_ControllerPublic_Member and use them in SortMem_ControllerPublic_Member? Or do I have to redefine them?
     
  16. Chris D

    Chris D XenForo Developer Staff Member

    I believe if you're extending an existing function then you could start your function with:

    PHP:
    parent::functionName();
    So something like this:

    PHP:
    <?php
     
    class SortMem_ControllerPublic_Member extends XFCP_SortMem_ControllerPublic_Member
    {
     
        public function 
    actionIndex()
        {
            
    parent::actionIndex();
            <
    rest of your code>
        }
     
    }
    That should keep the same variables as XenForo_ControllerPublic_Member.

    PS:

    Watermark add-on. I know, I know. I will get there :p
     
  17. MOZ

    MOZ Well-Known Member

    Thanks. As you can see I;m extending my reach and exploring new avenues on my own. :p
     
  18. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Because you want to change the order of the member list, you will need to basically redefine the entire function since you need to query the records again.
     
  19. MOZ

    MOZ Well-Known Member

    So it has to look like this:

    PHP:
    <?php
    class SortMem_ControllerPublic_Member extends XFCP_SortMem_ControllerPublic_Member
    {
    public function 
    actionIndex()
    {
    $userId $this->_input->filterSingle('user_id'XenForo_Input::UINT);
    if (
    $userId)
    {
    return 
    $this->responseReroute(__CLASS__'member');
    }
    else if (
    $this->_input->inRequest('user_id'))
    {
    return 
    $this->responseError(new XenForo_Phrase('posted_by_guest_no_profile'));
    }
     
    $userModel $this->_getUserModel();
     
    $username $this->_input->filterSingle('username'XenForo_Input::STRING);
    if (
    $username !== '')
    {
    $user $userModel->getUserByName($username);
    if (
    $user)
    {
    return 
    $this->responseRedirect(
    XenForo_ControllerResponse_Redirect::SUCCESS,
    XenForo_Link::buildPublicLink('members'$user)
    );
    }
    else
    {
    $userNotFound true;
    }
    }
    else
    {
    $userNotFound false;
    }
     
    $page $this->_input->filterSingle('page'XenForo_Input::UINT);
    $usersPerPage XenForo_Application::get('options')->membersPerPage;
     
    $criteria = array(
    'user_state' => 'valid',
    'is_banned' => 0
    );
     
    // users for the member list
    $users $userModel->getUsers($criteria, array(
    'join' => XenForo_Model_User::FETCH_USER_FULL,
    'perPage' => $usersPerPage,
    'page' => $page,
    'order' => 'message_count',
    'direction' => 'DESC'
    ));
     
    // most recent registrations
    $latestUsers $userModel->getLatestUsers($criteria, array('limit' => 8));
     
    // most active users (highest post count)
    $activeUsers $userModel->getMostActiveUsers($criteria, array('limit' => 12));
     
    $viewParams = array(
    'users' => $users,
     
    'totalUsers' => $userModel->countUsers($criteria),
    'page' => $page,
    'usersPerPage' => $usersPerPage,
     
    'latestUsers' => $latestUsers,
    'activeUsers' => $activeUsers,
     
    'userNotFound' => $userNotFound
    );
     
    return 
    $this->responseView('XenForo_ViewPublic_Member_List''member_list'$viewParams);
    }
     
    }
     
  20. Chris D

    Chris D XenForo Developer Staff Member

    I'm really pleased about that :)

    It's fun :D
     

Share This Page