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

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

$
0
0
I suspect the problem is your model load line in the view file. You don't need to do that at all.

Instead of your "$this->thing = $model->get<thing>();" lines you want "$this->thing = $this->get('<thing>');". The default model, which is the way you've (correctly) structured your model, will be loaded automatically and used.

Also I would suggest your namespace is badly named. Replacing the "Joomla" for something specific to you will keep your code out of the main Joomla namespace and better separated.

You also don't need the __construct method in the controller. The controller *does* need to be there, but you don't need to re-implement any methods that simply call their parents.
THanks for your help, I'll do all these modifications, but also have error, but another.

Now I see error:

"0 Incorrect controller class: display"

code for controller:

Code:

<?phpnamespace VPJoomla\Component\Faq\Administrator\Controller;use Joomla\CMS\MVC\Controller\AdminController;use Joomla\CMS\MVC\Factory\MVCFactoryInterface;use Joomla\CMS\Application\CMSApplication;use Joomla\Input\Input;defined('_JEXEC') or die;class FaqContentController extends AdminController {    public function getModel($name = 'FaqContent', $prefix = 'Administrator', $config = ['ignore_request' => true]){        return parent::getModel($name, $prefix, $config);    }    public function display($cachable = false, $urlparams = array()) {        return parent::display($cachable, $urlparams);    }}
code for model:

Code:

<?phpnamespace VPJoomla\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 using parent::getItems()    $items = parent::getItems();    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;}protected function populateState($ordering = 'a.id', $direction = 'desc'){    $app = Factory::getApplication();    $input = $app->input;    $search = $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search');    $this->setState('filter.search', $search);    $published = $this->getUserStateFromRequest($this->context . '.filter.published', 'filter_published', '');    $this->setState('filter.published', $published);    // Set the default ordering and direction if not already set    parent::populateState($ordering, $direction);}/* Prepare a faqcontentiten 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;}}}
code for view:

Code:

<?phpnamespace VPJoomla\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;class HtmlView extends BaseHtmlView {        protected $items;    protected $pagination;    protected $state;    public $filterForm;    public $activeFilters;         public function display($tpl = null) {                    $this->items      = $this->get('Items');            $this->pagination = $this->get('Pagination');            $this->state      = $this->get('State');                // Get filter form and active filters            $this->filterForm    = $this->get('FilterForm');            $this->activeFilters = $this->get('ActiveFilters');                // Add toolbar            $this->addToolBar();                // Display the view            parent::display($tpl);                // Set document title            $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');    }    public function setDocument(\Joomla\CMS\Document\Document $document): void {        $document->setTitle(Text::_("COM_FAQ"));    }}
Really strange...

Statistics: Posted by zeus07 — Wed Mar 27, 2024 11:10 pm



Viewing all articles
Browse latest Browse all 2139

Trending Articles



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