• 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?

MOZ

Well-known member
#1
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:



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
 

MOZ

Well-known member
#4
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
 

Jake Bunce

XenForo moderator
Staff member
#5
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.
 

Jake Bunce

XenForo moderator
Staff member
#6
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
What text program? Make sure the files are saved in plain text.
 

Jake Bunce

XenForo moderator
Staff member
#9
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.
 

MOZ

Well-known member
#15
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?
 

Chris D

XenForo developer
Staff member
#16
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
 

Jake Bunce

XenForo moderator
Staff member
#18
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.
 

MOZ

Well-known member
#19
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);
}
 
}