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

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

$
0
0
Joomla derives list view name by pluralizing the item view. If you stick with core MVC, that would be the convention to follow. But alternatively you can declare the list view name in your controller:

Code:

class FaqcontentitemController extends FormController {    protected $view_list = 'faqcontent';}
Thanks! Now it works good!

I have another questions about buttons in Toolbar , I mean buttons in Actions. Now, if I'll click on item state in list items - working publishing and unpublishing. But if I'll use button Actions - nothing works. I mean all buttons: Publish, Unpubkish, Archive, Trash.

How I can fix it? Maybe I should to add some methods in model?

This is FaqcontentModel.php:

Code:

<?phpnamespace VPJoomla\Component\Faq\Administrator\Model;use Joomla\CMS\Factory;use Joomla\CMS\MVC\Model\ListModel;use Joomla\Database\ParameterType;defined('_JEXEC') or exit();class FaqcontentModel extends ListModel {/** * Конструктор. * @param   array  $config  Массив с конфигурационными параметрами. */public function __construct($config = []){// Добавляем валидные поля для фильтров и сортировки.if (empty($config['filter_fields'])) {$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()    {        $items = parent::getItems();         return $items;    }/** * Метод для построения SQL запроса для загрузки списка данных. * @return  string  SQL запрос. */protected function getListQuery(): string{$db    = $this->getDatabase();        $query = $db->getQuery(true);//$query->select('*');//$query->from('#__faq_item');$query->select(            $this->getState(                'list.select',                [                    $db->quoteName('a.id'),                    $db->quoteName('a.title'),                    $db->quoteName('a.state'),                    $db->quoteName('a.publish_up'),$db->quoteName('a.ordering'),]            )        )->from($db->quoteName('#__faq_item', 'a'));        // Фильтр по состоянию полученному из запроса        $published = (string) $this->getState('filter.published');         if (is_numeric($published))        {            $query->where($db->quoteName('a.state') . ' = :published');            $query->bind(':published', $published, ParameterType::INTEGER);        }        elseif ($published === '')        {            $query->where('(' . $db->quoteName('a.state') . ' = 0 OR ' . $db->quoteName('a.state') . ' = 1)');        }         // Фильтр поиска по названию.        $search = $this->getState('filter.search');         if (!empty($search))        {            $search = $db->quote('%' . str_replace(' ', '%', $db->escape(trim($search), true) . '%'));            $query->where('(a.title LIKE ' . $search . ')');        }// Добавляем сортировку.$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);}protected function getStoreId($id = ''){// Compile the store id.$id .= ':' . $this->getState('filter.search');$id .= ':' . $this->getState('filter.published');return parent::getStoreId($id);}/* 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;}}    /**     * Method to change the published state of one or more records.     *     * @param array    &$pks   A list of the primary keys to change.     * @param integer $value  The value of the published state.     *     * @return  boolean  True on success.     *     * @since   4.0.0     */    public function publish(array &$pks, int $value = 1) {        if (empty($pks)) {            return false; // No records to update        }        $db = $this->getDatabase();        // Sanitize the value        $value = (int) $value;        try {            $query = $db->getQuery(true)                ->update($db->quoteName('#__faq_item'))                ->set($db->quoteName('state') . ' = ' . $value)                ->whereIn($db->quoteName('id'), $pks);            $db->setQuery($query);            $db->execute();            return true;        } catch (\Exception $e) {            return false;        }    }}

Statistics: Posted by zeus07 — Sat Mar 30, 2024 10:36 pm



Viewing all articles
Browse latest Browse all 1428

Trending Articles





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