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

Purpose of ViewPublic Files

Discussion in 'XenForo Development Discussions' started by sajal, Oct 12, 2016.

  1. sajal

    sajal New Member

    Hello All,

    I'm having a bit of hard time understanding the exact purpose of files under "ViewPublic".

    Let's say for example, the "XenForo_ViewPublic_Forum_List" view has "renderHtml" method that just initializes "renderedNodes" variable that's gonna be used in template. Couldn't we initialize the same in controller method itself as we initialize other variable as shown following?

    $viewParams = array(
    'nodeList' => $this->_getNodeModel()->getNodeDataForListDisplay(false, 0),
    'onlineUsers' => $this->_getSessionActivityList(),
    'boardTotals' => $this->_getBoardTotals(),
    'canViewMemberList' => $this->getModelFromCache('XenForo_Model_User')->canViewMemberList(),

    'threads' => $threads,

    'profilePosts' => $profilePosts,
    'canUpdateStatus' => XenForo_Visitor::getInstance()->canUpdateStatus()
    );

    Thanks,
    Sajal
     
  2. Chris D

    Chris D XenForo Developer Staff Member

    XenForo_ViewPublic_Forum_List is really a special case. To render the Node tree it needs to make use of the XenForo_View object and it traverses the node tree and all of its children to render the correct templates based on the definition of the node type's handler object. This wouldn't be appropriate in the Controller because conceptually the View and Controller layers should be kept separate when using MVC principles.
     
  3. sajal

    sajal New Member

    Thanks @Chris D, So I understand that whenever you need "XenForo_View" object to render other sub-templates as well in addition to those flat variables in controller, you should make your own View class and put the code there, right?
     
  4. Chris D

    Chris D XenForo Developer Staff Member

    Yes but not only that.

    It also enables you to make adjustments to the view for other types of response such as Xml and Json.

    9 times out of 10, you won't need it.
     
    Robust likes this.
  5. sajal

    sajal New Member

Share This Page