Quantcast
Channel: Joomla! Forum - community, help and support
Viewing all articles
Browse latest Browse all 2336

Joomla! 4.x Coding • How to fix error 00 Call to a member function get() on null ($listOrder)

$
0
0
Hi!

This is my first component for FAQ. It has several views:

Faq - base view for page info
Faqcontent - view for list of all questions
FaqContentItem - edit view for add or edit question.

Now I have this error on page faqcontent:

Code:

0 Call to a member function get() on null in JROOT/administrator/components/com_faq/tmpl/faqcontent/default.php:17
THis is code for file com_faq/tmpl/faqcontent/default.php:

Code:

<?phpdefined('_JEXEC') or exit();use Joomla\CMS\Button\PublishedButton;use Joomla\CMS\Button\TransitionButton;use Joomla\CMS\Component\ComponentHelper;use Joomla\CMS\Factory;use Joomla\CMS\HTML\HTMLHelper;use Joomla\CMS\Language\Text;use Joomla\CMS\Layout\LayoutHelper;use Joomla\CMS\Router\Route;use Joomla\CMS\Session\Session;$app            = Factory::getApplication();$doc            = Factory::getDocument();$listOrder = $this->escape($this->state->get('list.ordering'));$listDirn  = $this->escape($this->state->get('list.direction'));$saveOrder = $listOrder == 'a.ordering';$orderingColumn = 'publish_up';/** @var \Joomla\CMS\WebAsset\WebAssetManager $wa */$wa = $app->getDocument()->getWebAssetManager();$wa->useScript('table.columns')->useScript('multiselect');if ($saveOrder && !empty($this->items)) {    $saveOrderingUrl = 'index.php?option=com_faq&task=faqcontentitem.saveOrderAjax&tmpl=component&' . Session::getFormToken() . '=1';    HTMLHelper::_('draggable.draggable');}?><div class="container-fluid">    <div class="row">        <div class="col">            <form action="<?php echo Route::_('index.php?option=com_faq&view=faqcontent'); ?>" method="post" id="adminForm" name="adminForm">        <?php echo LayoutHelper::render('joomla.searchtools.default', ['view' => $this]); ?>            <?php if (empty($this->items)) : ?>                    <div class="alert alert-info">                        <span class="icon-info-circle" aria-hidden="true"></span><span class="visually-hidden"><?php echo Text::_('INFO'); ?></span>            <?php echo Text::_('JGLOBAL_NO_MATCHING_RESULTS'); ?>                    </div>            <?php else : ?>                    <table class="table itemList" id="faqList">                        <thead>                        <tr>                            <th width="1%"><?php echo HtmlHelper::_('grid.checkall'); ?></th>                            <th scope="col" class="w-1 text-center d-none d-md-table-cell">                    <?php echo HTMLHelper::_('searchtools.sort', '', 'a.ordering', $listDirn, $listOrder, null, 'asc', 'JGRID_HEADING_ORDERING', 'icon-sort'); ?>                            </th>                    <th scope="col" class="w-1 text-center">                <?php echo HTMLHelper::_('searchtools.sort', 'JSTAGE', 'ws.title', $listDirn, $listOrder); ?>                            </th>                            <th scope="col" class="w-1 text-center">                    <?php echo HTMLHelper::_('searchtools.sort', 'JSTATUS', 'a.state', $listDirn, $listOrder); ?>                            </th>                            <th scope="col" style="min-width:100px">                    <?php echo HTMLHelper::_('searchtools.sort', 'JGLOBAL_TITLE', 'a.title', $listDirn, $listOrder); ?>                            </th>                            <th scope="col" class="w-10 d-none d-md-table-cell text-center">                    <?php echo HTMLHelper::_('searchtools.sort', 'COM_FAQ_HEADING_DATE_' . strtoupper($orderingColumn), 'a.' . $orderingColumn, $listDirn, $listOrder); ?>                            </th>                            <th scope="col" class="w-3 d-none d-lg-table-cell">                    <?php echo HTMLHelper::_('searchtools.sort', 'JGRID_HEADING_ID', 'a.id', $listDirn, $listOrder); ?>                            </th>                        </tr>                        </thead>                        <tbody>                        <?php foreach ($this->items as $i => $item) : ?>                            <tr class="row<?php echo $i % 2; ?>" data-draggable-group="<?php echo $item->catid; ?>">                                <td>                                    <?php                                        $iconClass = '';                                        if (!$saveOrder) {                                            $iconClass = ' inactive tip-top hasTooltip" title="' . HTMLHelper::_('tooltipText', 'JORDERINGDISABLED');                                        }                                    ?>                                    <span class="sortable-handler<?php echo $iconClass ?>">                                        <span class="icon-menu" aria-hidden="true"></span>                                    </span>                                    <input type="text" style="display:none" name="order[]" size="5" value="<?php echo $row->ordering; ?>" class="width-20 text-area-order" />                                </td>                                <td class="text-center">                        <?php echo $item->state; ?>                                </td>                                <td>                                    <a href="/<?php echo Route::_('index.php?option=com_faq&task=faqcontentitem.edit&id=' . (int) $item->id); ?>" title="<?php echo Text::_('JACTION_EDIT'); ?>">                                             <?php echo $this->escape($item->title); ?>                                    </a>                                </td>                                <td class="text-center">                        <?php echo $item->published; ?>                                </td>                                <td class="text-center">                        <?php echo HTMLHelper::_('grid.id', $i, $item->id); ?>                                </td>                            </tr>                        <?php endforeach; ?>                        </tbody>                    </table>            <?php echo $this->pagination->getListFooter(); ?>                <?php endif; ?>                <input type="hidden" name="task" value="">                <input type="hidden" name="boxchecked" value="0">            <?php echo HTMLHelper::_('form.token'); ?>            </form>        </div>    </div></div>
This is the code for file src/Model/FaqcontentModel.php

Code:

<?phpnamespace Joomla\Component\Faq\Administrator\Model;use Joomla\CMS\Factory;use Joomla\CMS\MVC\Model\ListModel;defined('_JEXEC') or exit();class FaqContentModel extends ListModel {/** * Конструктор. * @param   array  $config  Массив с конфигурационными параметрами. */public function __construct($config = []){// Добавляем валидные поля для фильтров и сортировки.$config['filter_fields'] = array(            'id', 'a.id',            'title', 'a.title',            'ordering', 'a.ordering',            'state', 'a.state',            'publish_up', 'a.publish_up'        );parent::__construct($config);}/**     * Method to get a list of items.     *     * @return  mixed   An array of data items on success, false on failure.     */    public function getItems()    {        // Get the query for retrieving items        $query = $this->getQuery();        // Set the query limits and execute        $this->setState('list.limit', 0);        $this->setState('list.start', 0);        $this->setQuery($query);        // Get the items from the query        $items = $this->getList();        return $items;    }/** * Метод для построения SQL запроса для загрузки списка данных. * @return  string  SQL запрос. */protected function getQuery(): string{$db = $this->getDbo();        $query = $db->getQuery(true);$query->select('*');$query->from('#__faq_item');        /* Add Searching */$state = $this->getState('filter.state');if (is_numeric($state)){$query->where('state = ' . (int) $state);}elseif ($state === ''){$query->where('(state = 0 OR state = 1)');}$search = $this->getState('filter.search');if (!empty($search)){$search = $db->quote('%' . $db->escape($search, true) . '%', false);$query->where('title LIKE ' . $search);}        $published = $this->getState('filter.published');        if (is_numeric($published)) {                $query->where($db->quoteName('published') . ' = ' . $db->quote($published));        } elseif ($published === '') {                $query->whereIn($db->quoteName('published'), array(0, 1));        }// Добавляем сортировку.$orderCol  = $this->state->get('list.ordering', 'id');$orderDirn = $this->state->get('list.direction', 'desc');$query->order($db->escape($orderCol . ' ' . $orderDirn));return $query;}/* Prepare a helloworld record for saving in the database */protected function prepareTable($table){// Set ordering to the last item if not setif (empty($table->ordering)){$db = $this->getDbo();$query = $db->getQuery(true)->select('MAX(ordering)')->from('#__faq_item');$db->setQuery($query);$max = $db->loadResult();$table->ordering = $max + 1;}}}
THis is the code for src/View/FaqContent/HtmlView.php

Code:

<?phpnamespace Joomla\Component\Faq\Administrator\View\FaqContent;defined('_JEXEC') or die;use Joomla\CMS\Language\Text;use Joomla\CMS\Toolbar\ToolbarHelper;use Joomla\CMS\Factory;use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;/** * @package     Joomla.Administrator * @subpackage  com_faq * * @copyright   Copyright (C) 2022 Abdul waheed. All rights reserved. * @license     GNU General Public License version 3; see LICENSE */class HtmlView extends BaseHtmlView {        /**     * Display the main "FaqContent" view     *     * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.     * @return  void     */    protected $items;    protected $pagination;    protected $state;public $filterForm;public $activeFilters;         function display($tpl = null) {        $this->items         = $this->get('Items');    $this->pagination    = $this->get('Pagination');    $this->state         = $this->get('State');    $this->filterForm    = $this->get('FilterForm');    $this->activeFilters = $this->get('ActiveFilters');        $this->addToolBar();        parent::display($tpl);        $this->setDocument(Factory::getDocument());    }    protected function addToolBar() {        ToolbarHelper::title(Text::_("COM_FAQ_LIST"), 'question-circle');        ToolbarHelper::addNew('faqcontentitem.add');        ToolbarHelper::editList('faqcontentitem.edit');        ToolbarHelper::publish('faqcontentitem.publish', 'JTOOLBAR_PUBLISH', true);        ToolbarHelper::unpublish('faqcontentitem.unpublish', 'JTOOLBAR_UNPUBLISH', true);        ToolbarHelper::deleteList('', 'faqcontentitem.delete');    }    /**     * Set document title     */    public function setDocument(\Joomla\CMS\Document\Document $document): void {        $document->setTitle(Text::_("COM_FAQ"));    }}
THis is the code for file src/Controller/FaqcontentController.php:

Code:

<?phpuse Joomla\CMS\MVC\Controller\AdminController;defined('_JEXEC') or die;class FaqContentController extends AdminController {        public function getModel($name = 'FaqContent', $prefix = 'Faq', $config = array('ignore_request' => true)) {                return parent::getModel($name, $prefix, $config);        }}
I want to fix this error and get list with questions, sorting, filter and ordering.
help please to fix error and maybe someone can give me manual.

Thanks

Statistics: Posted by zeus07 — Tue Mar 26, 2024 12:04 am



Viewing all articles
Browse latest Browse all 2336

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>