How get the XenForo_View instance from Controller?

Fuhrmann

Well-known member
Hi!

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.
 
Ok, I could get this working, I just do not know if this is the right way. This is what I have done:

PHP:
/* 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);
 
Why aren't you doing this in an own view object?

Because I am doing this inside a callback for a page. I am doing another tutorial on how to show a post inside a page, then I am using a callback for that page to get the desired post.
 
Ok, get it. This is the easy way (the other was the hard):

PHP:
$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.
 
Top Bottom