XF 1.0 Editing Templates and Defining a Callback for Pages

Kier

XenForo developer
Staff member
This is test site on localhost with screengrab of the error
The template is attempting to loop through $onlineUsers['records'] but your are setting your variable as $users.

Take this line:
PHP:
$response->params['users'] = $userModel->getLatestUsers(array(), array('limit'=> 5));
and replace it with this:
PHP:
$response->params['onlineUsers'] = $userModel->getLatestUsers(array(), array('limit'=> 5));
 

MGSteve

Well-known member
I don't believe that's actually possible, as both htaccess and WebDAV use HTTP Basic Auth.
I know this is an old thread, but I ran into this issue as well. For anyone who also runs into it, you can add this into your .htaccess file and it basically removes the webdav file from the HTTP Auth protection, allowing you to get access via WebDav.

Code:
<Files admindav.php>
order allow,deny
allow from all
satisfy any
</Files>
You can of course change it to below which should limit access to a specific IP address. (I haven't tested it though.)

Code:
<Files admindav.php>
order deny, allow
deny from all
allow from 123.123.123.123
satisfy any
</Files>
 
A

account8226

Guest
Hello, I am making a page following this tutorial, but when I use "respond" I have the following error : please use a valide callback method.



Thanks.
 

x_Stricken_x

Active member
It means the callback method (either controller, or action) isn't valid - either the class can't be loaded, or the action is invalid (usually doesn't exist, or has a typo).
 

Cory Booth

Well-known member
I just enabled this feature using the demo here...
I got it all to work...

The question is, what is the proper way to return the HTML inside the Template HTML area?
Or do I have to insert it into the template?

****EDIT: Just used the PAGE_CONTAINER html.
 

Zach Sugano

Member
Where do I put the php class file? I am trying to just make a simple page where I can get data from a mysql database and display it in a table.
 

Cory Booth

Well-known member
OK, I followed the video from Kier...
So this is what I did - maybe it'll help...

Under folder library - create a folder "Prod"
In this... Create two folders - "Model" and "PageCallBack"
In Model - create a file "Post.php"
In this file place
Code:
<?php
class Prod_Model_Post extends XenForo_Model_Post
{
    public function getMostRecentPosts($maxResults, array $viewingUser = array())
    {
        $postIds = $this->_getDb()->fetchCol(
            $this->limitQueryResults('
                SELECT post_id
                FROM xf_post
                ORDER BY post_date DESC
            ', $maxResults * 2
            )
        );
        $postResults = $this->getPostsByIds($postIds, array(
            'join' => XenForo_Model_Post::FETCH_THREAD
                | XenForo_Model_Post::FETCH_FORUM
                | XenForo_Model_Post::FETCH_USER
                | XenForo_Model_Post::FETCH_USER_PROFILE,
            'permissionCombinationId' => $viewingUser['permission_combination_id']
        ));
        $posts = array();
        foreach ($postResults AS $postId => $post)
        {
            $posts[$post['post_date'] . '_' . $post['post_id']] = $post;
        }
        krsort($posts);
        return array_slice($posts, 0, $maxResults, true);
    }
}



In the "PageCallBack" make a file called "AHPages.php"
In this file place the following code:

Code:
<?php
class Prod_PageCallback_AHPages
{
    public static function respond(XenForo_ControllerPublic_Abstract $controller, XenForo_ControllerResponse_Abstract $response)
    {
        $visitor = XenForo_Visitor::getInstance()->toArray();
        $sessionModel = $controller->getModelFromCache('XenForo_Model_Session');
        $response->params['onlineUsers'] = $sessionModel->getSessionActivityQuickList(
            $visitor,
            array('cutOff' => array('>', $sessionModel->getOnlineStatusTimeout())),
            ($visitor['user_id'] ? $visitor : null)
        );
        // fetch recent registrations
        $userModel = $controller->getModelFromCache('XenForo_Model_User');
        $response->params['users'] = $userModel->getLatestUsers(array(), array('limit' => 5));
        // fetch most recent posts
        $response->params['posts'] = self::_getPostModel($controller)->getMostRecentPosts(5, $visitor);
        $response->templateName = 'template_ahpages';
    }
    /**
     * @return Dev_Model_Post
     */
    protected static function _getPostModel(XenForo_ControllerPublic_Abstract $controller)
    {
        return $controller->getModelFromCache('Prod_Model_Post');
    }
}

Now when creating a new "Page"
In the PHP callback insert:

Prod_PageCallback_AHPages and respond
 

GabrielVH

Member
I know this is an old thread, but I can't find anything else (unless someone has a link?).

I've got my class setup in /library/PGMemberList/PageCallback/Members.php and I'm just using the example code from the video at the moment, modified with my class name:

Code:
<?php
 
class PGMemberList_PageCallback_Members {
 
  public static function respond(XenForo_ControllerPublic_Abstract $controller, XenForo_ControllerResponse_Abstract $response)
 
    $userModel = $controller->getModelFromCache('XenForo_Model_User');
    $response->params['users'] = $userModel->getLatestUsers(array(), array('limit' => 5));
 
    $response->templateName = 'pgmember_list';
  }
 
}
My template file just has a foreach loop of the user title as in the video.

But I can't save the page in the ACP when I enter the class name and method? Looking at the XHR request the page makes, the server responds with Internal Server Error 500.
I've also edited the database page entry with my class name and method, but then the resulting page node just shows up blank. Even with debug mode on for my IP Address I don't get any information about the error.

Any ideas?
 

Jeremy

Well-known member
I know this is an old thread, but I can't find anything else (unless someone has a link?).

I've got my class setup in /library/PGMemberList/PageCallback/Members.php and I'm just using the example code from the video at the moment, modified with my class name:

Code:
<?php
 
class PGMemberList_PageCallback_Members {
 
  public static function respond(XenForo_ControllerPublic_Abstract $controller, XenForo_ControllerResponse_Abstract $response)
 
    $userModel = $controller->getModelFromCache('XenForo_Model_User');
    $response->params['users'] = $userModel->getLatestUsers(array(), array('limit' => 5));
 
    $response->templateName = 'pgmember_list';
  }
 
}
My template file just has a foreach loop of the user title as in the video.

But I can't save the page in the ACP when I enter the class name and method? Looking at the XHR request the page makes, the server responds with Internal Server Error 500.
I've also edited the database page entry with my class name and method, but then the resulting page node just shows up blank. Even with debug mode on for my IP Address I don't get any information about the error.

Any ideas?
Post your issue in Development Discussions, just so we know you are licensed. I think non-licensed people go post here. But its also easier to track your issue there.
 

gginni

Active member
Hi,

I created a page node using this tutorial and I was successful but in side bar "members Online Now are shown as 0"

Pasting screenshot of another user where he was also getting Members Online Now as 0.

Please tell me how to show correct members count? And I also want to show other side bars like new threads/new replies ... how to show them?
 

Teapot

Well-known member
Please tell me how to show correct members count? And I also want to show other side bars like new threads/new replies ... how to show them?
Just to quickly answer your first question:

The template is attempting to loop through $onlineUsers['records'] but your are setting your variable as $users.

Take this line:
PHP:
$response->params['users'] = $userModel->getLatestUsers(array(), array('limit'=> 5));
and replace it with this:
PHP:
$response->params['onlineUsers'] = $userModel->getLatestUsers(array(), array('limit'=> 5));
 
Top