1

view.html.php

class gezcViewVliegtuigen extends JViewLegacy
{ 
    protected $editID = 0;

     // if task is not specifiek in the url als parameter, display will be used
    function display($tpl = null)
    {
        $app = JFactory::getApplication();
        $context = "com_gezc.list.site.vliegtuigen";

        // aanroep URL
        $uri = JFactory::getURI();
        $this->requestURL = $uri->toString();

        // Assign data to the view
        $this->vliegtuigen = $this->get('Vliegtuigen');
        
        $this->paginas = new JPagination($this->get('Aantal'), $this->get('Start') , $this->get('Limit'));

        $this->state = $this->get('State');
        $this->filter_order     = $app->getUserStateFromRequest($context.'filter_order', 'filter_order');
        $this->filter_order_Dir = $app->getUserStateFromRequest($context.'filter_order_Dir', 'filter_order_Dir', 'asc', 'cmd');
        $this->filterForm       = $this->get('FilterForm');
        $this->activeFilters    = $this->get('ActiveFilters');

        // Check for errors.
        if (count($errors = $this->get('Errors')))
        {
            JLog::add(implode('<br />', $errors), JLog::WARNING, 'jerror');

            return false;
        }

        // Set the toolbar
        $this->addToolBar();

        // Set the document
        $this->setDocument();

        // Display the view
        parent::display($tpl);      
    }
    
    protected function addToolBar()
    {
        JToolbarHelper::title(JText::_('COM_HELLOWORLD_MANAGER_HELLOWORLDS'));  
        JToolbarHelper::addNew('vliegtuigen.add');
    }   

    protected function setDocument() 
    {
        $isNew = true; // ($this->item->id < 1);    TODO
        $document = JFactory::getDocument();
        $document->setTitle($isNew ? JText::_('COM_GEZC_VLIEGTUIGEN_TITEL_CREATING') :
                JText::_('COM_GEZC_VLIEGTUIGEN_TITEL_EDITING'));
    }
}

default.php

JHtml::_('behavior.framework', true);

// TODO 
JHtml::script("https://cdn.jsdelivr.net/npm/uikit@3.4.6/dist/js/uikit.min.js");
JHtml::script("https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js");
JHtml::stylesheet('https://cdn.jsdelivr.net/npm/uikit@3.4.6/dist/css/uikit.min.css');


$listOrder     = $this->escape($this->filter_order);
$listDirn      = $this->escape($this->filter_order_Dir);
?>
<h1>Vliegtuigen</h1>

<form action="<?php echo $this->requestURL; ?>" method="post" id="adminForm" name="adminForm">
<div class="row-fluid">
        <div class="span6">
            <?php
                echo JLayoutHelper::render(
                    'joomla.searchtools.default',
                    array('view' => $this)
                );
            ?>
        </div>
    </div>

    <div class="uk-overflow-auto">
        <table class="table uk-table-striped uk-table-small uk-table-hover" id="tableX">
            <thead>
....
            </thead>
            <tfoot>
....
            </tfoot>
            <tbody>
....           
            </tbody>
        </table>
    </div>
    <input type="hidden" name="task" value=""/>
    <input type="hidden" name="boxchecked" value="0"/>  
    <input type="hidden" name="filter_order" value="<?php echo $listOrder; ?>"/>
    <input type="hidden" name="filter_order_Dir" value="<?php echo $listDirn; ?>"/>

    <?php echo JHtml::_('form.token'); ?>  
</form>

The table and the search bar is nice displayed. The filter works correctly, but for some reason the toolbar is not displayed.

I tried to check the implementation in Joomla, but there is a lot of magic going on under the hood. Can some explain what I am doing wrong and how it works within de Joomla framework?

  • Welcome to JSE. Please take our tour while you wait for support. Consider giving yourself a more human username and perhaps tell us a little about yourself /your Joomla experience in your profile. – mickmackusa Aug 4 at 20:10
  • Odd...I dropped your code into an existing component and the New button appears just fine... – Grant G Aug 4 at 23:52
  • 1
    Is this by chance a frontend view? – Sharky Aug 5 at 8:26
  • Yes, this is a frontend view. It is located in the site folder within the custom component. Basically the logged in user need to be able to add a record when using the frontend. – user3412673 Aug 5 at 9:29
3

Toolbar isn't really supported in frontend. In backend it's rendered by mod_toolbar module which is only available in backend.

You can still render the toolbar in frontend using this code but it may not necessarily work correctly:

echo Joomla\CMS\Toolbar\Toolbar::getInstance('toolbar')->render('toolbar');
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.