What am I doing wrong?

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:
2012-07-18_124441.png



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
 
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
 
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.
 
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.
 
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.
 
Are you sure you are working with the correct installation of XF? I see both Windows and Linux paths in your posts.
 
Weird isue, it was a bad save, I wrote the code again and this time both the files were half the size. :confused:
 
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?
 
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
 
Thanks. As you can see I;m extending my reach and exploring new avenues on my own. :P
 
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.
 
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);
}
 
}
 
Top Bottom