1. 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?

Discussion in 'XenForo Development Discussions' started by Fuhrmann, Feb 16, 2012.

  1. Fuhrmann

    Fuhrmann 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.
  2. Fuhrmann

    Fuhrmann 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);
  3. ragtek

    ragtek Guest

    Why aren't you doing this in an own view object?
  4. Fuhrmann

    Fuhrmann Well-Known Member

    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.
  5. Fuhrmann

    Fuhrmann 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);
    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.

Share This Page