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

What is a View and how to use it ?

Discussion in 'XenForo Development Discussions' started by Evaelis, Mar 26, 2016.

  1. Evaelis

    Evaelis New Member

    Hello there!
    I actually want to create a custom page for my addon. So I first added it to the navbar :
    PHP:
    class DonatorHandler_Navigation_Tabs
    {
            public static function 
    addNavbarTab(array &$extraTabs$selectedTabId)
            {  
                    
    $extraTabs['donation'] = array(
                        
    'title' => new XenForo_Phrase('donatorhandler_navbar_title'),
                        
    'href'  => XenForo_Link::buildPublicLink('donation'),
                        
    'selected' => ($selectedTabId == new XenForo_Phrase('donatorhandler_navbar_title')),
                        
    'position'  =>  'end'
                    
    );
            }
    }
    Then I needed to create a route, as I don't need any params at the moment here is the code :
    PHP:
    class DonatorHandler_Route_Prefix_Public implements XenForo_Route_Interface
    {
        public function 
    match($routePathZend_Controller_Request_Http $requestXenForo_Router $router)
        {
            return 
    $router->getRouteMatch('DonatorHandler_ControllerPublic_Donation''index''donation');
        }
        public function 
    buildLink($originalPrefix$outputPrefix$action$extension$data, array &$extraParams)
        {
            return 
    XenForo_Link::buildBasicLink($outputPrefix$action$extension);
        }
    }
    Here are the question :
    First the getRouteMatch use my DonatorHandler_ControllerPublic_Donation which call a responseView.
    PHP:
    class DonatorHandler_ControllerPublic_Donation extends XenForo_ControllerPublic_Abstract
    {
        public function 
    actionIndex()
        {
            
    $viewParams = array(
                
    'userNotFound' => true,
            );
            return 
    $this->responseView('DonatorHandler_ViewPublic_Donation_View''donation'$viewParams);
        }
    }
    PHP:
    class DonatorHandler_ViewPublic_Donation_View extends XenForo_ViewPublic_Base
    {
        public function 
    renderHtml()
        {
          
        }
    }
    What is the ViewPublic used for ? What can I modify with it ?

    I took the basic code from the Member page (I left the userNotFound for my test)
     
  2. Liam W

    Liam W Well-Known Member

    The view class is used to change parameters or output, such as if json is needed.

    You don't actually need to include a view class (you can use an empty string), although you can also specify a non-existent class which will allow other add-ons to extend it and add their own logic.

    For standard HTML templates, no view class is needed.

    Liam
     
  3. Evaelis

    Evaelis New Member

    I will try to manipulate them and see what happens.
    However I don't think I need them for this addon.
    Thank you Liam!
     

Share This Page