What is a View and how to use it ?

Evaelis

Active 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($routePath, Zend_Controller_Request_Http $request, XenForo_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)
 
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
 
I will try to manipulate them and see what happens.
However I don't think I need them for this addon.
Thank you Liam!
 
Back
Top Bottom