• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

How get the XenForo_View instance from Controller?

Fuhrmann

Well-known member
#1
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.
 

Fuhrmann

Well-known member
#2
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);
 

Fuhrmann

Well-known member
#5
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.