How get the XenForo_View instance from Controller?


Well-known member

So, I have the $controller and the controller $response from a page. But I need to get the XenForo_View instance of the controller, is this possible?

What I am trying to do is parse the attachments from a post inside a page, but to do this I need a view.


Well-known member
Ok, I could get this working, I just do not know if this is the right way. This is what I have done:

/* Get the front controller instance */
        $fc = $GLOBALS['fc'];
        /* Get the view rendered */
        $viewRenderer = $fc->getDependencies()->getViewRenderer($fc->getResponse(), $controller->getResponseType(), $fc->getRequest());
        /* Create a new view */
        $view = new XenForo_ViewPublic_Base($viewRenderer, $fc->getResponse());
        /* Create the parser */
        $bbCodeParser = new XenForo_BbCode_Parser(XenForo_BbCode_Formatter_Base::create('Base', array('view' => $view)));
        /* Parse options */
        $bbCodeOptions = array(
            'states' => array(
                'viewAttachments' => true
        /* parse the post message */
        $post['messageParsed'] = XenForo_ViewPublic_Helper_Message::getBbCodeWrapper($post, $bbCodeParser, $bbCodeOptions);


Well-known member
Ok, get it. This is the easy way (the other was the hard):

$viewParams = array (
            'post' => $post,
            'title' => $thread['title']
        $response = $controller->responseView('ShowAPost_ViewPublic_View', $response->params['templateTitle'], $viewParams);
        return $response;
Then I just need to create the view and parse the BBCode using the parser. Just to remeber who else reading this, that this is inside a page callback.