XF 2.0 Trying to move from XF1.X to XF2.1 api

  • Thread starter Thread starter Deleted member 110473
  • Start date Start date
D

Deleted member 110473

Guest

I found the above resource used for xf 1.x, and I noticed a lot of the calls don't transfer to xf 2.x now. I am a new developer, and would like some help. If anyone can point me to resources or changelogs I can look at that are for developers that sort help you figure out what became what, that will be great!

I don't have a lot of changes so far:
PHP:
<?php
/**
* How to show a post inside a page.
* This code have all the necessary to show a post inside a page. Just read the comments.
* Fuhrmann
*/

namespace Pages;

class ShowAPost
{
    public static function showAPostInPage(
        \XF\Pub\Controller\AbstractController $controller,
        \XF\Mvc\Reply\AbstractReply &$response)
    {
        /* Set the ID of the post to be loaded */
        $postId = 1;

        /* Create a new ControllerHelper that will help us to get the post */
        $ftpHelper = new XenForo_ControllerHelper_ForumThreadPost($controller);

        /* Use the ControllerHelper to see if the post we want to get is viewable by the user browsing */
        list($post, $thread) = $ftpHelper->assertPostValidAndViewable($postId);

        /* If the post has attachments */
        if ($post['attach_count'] > 0)
        {
            /* Let's get all the attachments of this post, if exists  */
            $attachmentModel = XenForo_Model::create('XenForo_Model_Attachment');
            $attachments = $attachmentModel->getAttachmentsByContentId('post', $postId);
            foreach ($attachments AS $attachment)
            {
                /* Insert into the post data the attachments */
                $post['attachments'][$attachment['attachment_id']] = $attachmentModel->prepareAttachment($attachment)
;
            }
        }

        /* These parameters will be used in our template. We need to pass them into the response view. The $post para
m will be used too in the XenForo_ViewPublic instance */
        $viewParams = array (
            'post' => $post,
            'title' => $thread['title']
        );

        /* This way our post will be parsed and the aattachments too. :) */
        $response = $controller->responseView('ShowAPost_View', $response->params['templateTitle'], $viewParams);

        /* Return the response, finally!*/
        return $response;
    }
}
 
Back
Top Bottom