สอบถาม error หน้า view Component

ถามตอบ ปัญหาการพัฒนา Extension ไม่ว่าจะเป็น Module plugin Component หรือ แม้แต่ template การปรับแต่งโค้ด Joomla ต่างๆ ทุกเวอร์ชั่น 1.5 2.5 หรือ 3.x

Moderator: mindphp, ผู้ดูแลกระดาน

ภาพประจำตัวสมาชิก
Thanapoom1514
PHP VIP Members
PHP VIP Members
โพสต์: 4329
ลงทะเบียนเมื่อ: 04/07/2022 9:46 am

สอบถาม error หน้า view Component

โพสต์ที่ยังไม่ได้อ่าน โดย Thanapoom1514 »

ผมกำลังศึกษา Component ใน joomla 3 อยู่ ซึ่งตอนนี้ทำในส่วน view admin ครับ ซึ่งมันขึ้น error ครับ แก้ยังไงหรอครับ

ลิงก์หน้า view

โค้ด: เลือกทั้งหมด

http://localhost/Joomla_3.10.11/administrator/index.php?option=com_mexample&view=customers
An error has occurred.
0 Call to a member function getGroup() on bool
Joomla Development-1.png
Joomla Development-1.png (39 KiB) Viewed 2576 times
ตำแหน่งไฟล์ view
Joomla Development-2.png
Joomla Development-2.png (11.74 KiB) Viewed 2576 times
ไฟล์ view.html.php

โค้ด: เลือกทั้งหมด

<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_mexample
 *
 * @copyright   (C) 2007 Open Source Matters, Inc. <https://www.joomla.org>
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

class MExampleViewCustomers extends Joomla\CMS\MVC\View\HtmlView
{
    public 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);
    }

    public function addToolbar()
    {
        \Joomla\CMS\Toolbar\ToolbarHelper::title(JText::_('COM_MEXAMPLE_CUSTOMERS'));
        \Joomla\CMS\Toolbar\ToolbarHelper::addNew('customer.add');
        \Joomla\CMS\Toolbar\ToolbarHelper::editList('customer.edit');
        \Joomla\CMS\Toolbar\ToolbarHelper::deleteList(JText::_('COM_MEXAMPLE_ARE_YOU_SURE'), 'customers.remove');
        \Joomla\CMS\Toolbar\ToolbarHelper::preferences('com_mexample');
    }
}
ไฟล์ default.php

โค้ด: เลือกทั้งหมด

<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_mexample
 *
 * @copyright   (C) 2007 Open Source Matters, Inc. <https://www.joomla.org>
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

$listOrder = $this->escape($this->state->get('list.ordering'));
$listDirn  = $this->escape($this->state->get('list.direction'));
?>
<form action="<?php echo JRoute::_('index.php?option=com_mexample&view=customers'); ?>" method="post" name="adminForm" id="adminForm">
    <?php if (!empty($this->sidebar)) : ?>
        <div id="j-sidebar-container" class="span2">
            <?php echo $this->sidebar; ?>
        </div>
        <div id="j-main-container" class="span10">
    <?php else : ?>
        <div id="j-main-container">
    <?php endif; ?>
            <?php
            // Search tools bar
            echo JLayoutHelper::render('joomla.searchtools.default', array('view' => $this));
            ?>
            <?php if (empty($this->items)) : ?>
                <div class="alert alert-no-items">
                    <?php echo JText::_('JGLOBAL_NO_MATCHING_RESULTS'); ?>
                </div>
            <?php else : ?>
                <table class="table table-striped" id="categoryList">
                    <thead>
                        <tr>
                            <th width="1%">
                                <?php echo JHtml::_('grid.checkall'); ?>
                            </th>
                            <th width="1%" class="nowrap hidden-phone">
                                <?php echo JHtml::_('searchtools.sort', 'JGRID_HEADING_ID', 'a.id', $listDirn, $listOrder); ?>
                            </th>
                        </tr>
                    </thead>
                    <tfoot>
                        <tr>
                            <td colspan="<?php echo $columns; ?>">
                                <?php echo $this->pagination->getListFooter(); ?>
                            </td>
                        </tr>
                    </tfoot>
                    <tbody>
                    <?php
                    foreach ($this->items as $i => $item) : ?>
                            <tr class="row<?php echo $i % 2; ?>">
                                <td class="center">
                                    <?php echo JHtml::_('grid.id', $i, $item->id); ?>
                                </td>
                            <td class="hidden-phone">
                                <span title="<?php echo sprintf('%d-%d', $item->lft, $item->rgt); ?>">
                                    <?php echo (int) $item->id; ?></span>
                            </td>
                        </tr>
                    <?php endforeach; ?>
                    </tbody>
                </table>
                <?php // Load the batch processing form if user is allowed ?>
                <?php if ($user->authorise('core.create', 'com_tags')
                    && $user->authorise('core.edit', 'com_tags')
                    && $user->authorise('core.edit.state', 'com_tags')) : ?>
                    <?php echo JHtml::_(
                        'bootstrap.renderModal',
                        'collapseModal',
                        array(
                            'title'  => JText::_('COM_TAGS_BATCH_OPTIONS'),
                            'footer' => $this->loadTemplate('batch_footer'),
                        ),
                        $this->loadTemplate('batch_body')
                    ); ?>
                <?php endif; ?>
            <?php endif; ?>

            <input type="hidden" name="task" value="" />
            <input type="hidden" name="boxchecked" value="0" />
            <?php echo JHtml::_('form.token'); ?>
        </div>
</form>
:gfb:
ภาพประจำตัวสมาชิก
tsukasaz
PHP VIP Members
PHP VIP Members
โพสต์: 21988
ลงทะเบียนเมื่อ: 18/04/2012 9:39 am

Re: สอบถาม error หน้า view Component

โพสต์ที่ยังไม่ได้อ่าน โดย tsukasaz »

เช็คไฟล์ ชื่อ filter_customers.xml ในโฟลเดอร์ models/forms ว่ามีไหม
The last bug isn't fixed until the last user is dead. (Sidney Markowitz, 1995)
ภาพประจำตัวสมาชิก
Thanapoom1514
PHP VIP Members
PHP VIP Members
โพสต์: 4329
ลงทะเบียนเมื่อ: 04/07/2022 9:46 am

Re: สอบถาม error หน้า view Component

โพสต์ที่ยังไม่ได้อ่าน โดย Thanapoom1514 »

tsukasaz เขียน: 01/02/2023 9:03 am เช็คไฟล์ ชื่อ filter_customers.xml ในโฟลเดอร์ models/forms ว่ามีไหม
ขอบคุณครับ ในส่วนไฟล์ filter_customers.xml สร้างไปแล้วครับ แต่ไม่ได้ใส่โค้ด xml ไปครับ ซึ่งในตอนนี้เปิดหน้า view ได้แล้วครับ

โค้ด: เลือกทั้งหมด

<?xml version="1.0" encoding="utf-8"?>
<root>
</root>
Joomla Development-1.png
Joomla Development-1.png (51.33 KiB) Viewed 2562 times
:gfb:
ภาพประจำตัวสมาชิก
Thanapoom1514
PHP VIP Members
PHP VIP Members
โพสต์: 4329
ลงทะเบียนเมื่อ: 04/07/2022 9:46 am

Re: สอบถาม error หน้า view Component

โพสต์ที่ยังไม่ได้อ่าน โดย Thanapoom1514 »

สอบถามเพิ่มครับ พอผมกด New เพิ่มข้อมูลในฟอร์มแล้วกดบันทึกพอมาหน้าที่รายการ customers ขึ้น Error แบบนี้ครับ
An error has occurred.
0 Call to a member function authorise() on null
Joomla Development-1.png
Joomla Development-1.png (13.38 KiB) Viewed 2376 times
models ไฟล์ customers.php

โค้ด: เลือกทั้งหมด

class MExampleModelCustomers extends Joomla\CMS\MVC\Model\ListModel
{
    public function __construct($config = array())
	{
		if (empty($config['filter_fields']))
		{
			$config['filter_fields'] = array(
				'id', 'a.id',
				
			);
		}

		parent::__construct($config);
	}

    protected function populateState($ordering = 'a.id', $direction = 'asc')
	{
		$search = $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search');
		$this->setState('filter.search', $search);

		// Load the parameters.
		$params = JComponentHelper::getParams('com_mexample');
		$this->setState('params', $params);

		// List state information.
		parent::populateState($ordering, $direction);
	}

    protected function getListQuery()
	{
		// Create a new query object.
		$db = $this->getDbo();
		$query = $db->getQuery(true);
		
        $query->select('*')->from($db->qn('#__mexample_customers', 'a'));

		// Filter by search in title
		$search = $this->getState('filter.search');

		if (!empty($search))
		{
			if (stripos($search, 'id:') === 0)
			{
				$query->where('a.id = ' . (int) substr($search, 3));
			}
			else
			{
				$search = $db->quote('%' . str_replace(' ', '%', $db->escape(trim($search), true) . '%'));
				$query->where('(a.title LIKE ' . $search . ' OR a.alias LIKE ' . $search . ' OR a.note LIKE ' . $search . ')');
			}
		}


		// Add the list ordering clause
		$listOrdering = $this->getState('list.ordering', 'a.id');
		$listDirn = $db->escape($this->getState('list.direction', 'ASC'));
        $query->order($db->escape($listOrdering) . ' ' . $listDirn);
		// echo $query->__toString(); exit();
		return $query;
	}
}
:gfb:
ภาพประจำตัวสมาชิก
tsukasaz
PHP VIP Members
PHP VIP Members
โพสต์: 21988
ลงทะเบียนเมื่อ: 18/04/2012 9:39 am

Re: สอบถาม error หน้า view Component

โพสต์ที่ยังไม่ได้อ่าน โดย tsukasaz »

แนะนำว่าเวลาพัฒนาให้เปิดโหมด debug ใน joomla ด้วยครับ มันจะแจ้งว่าไฟล์ไหน บรรทัดไหน

ส่วนในปัญหานี้น่าจะอยู่ที่ไฟล์ default.php ในส่วน view ของ customers
The last bug isn't fixed until the last user is dead. (Sidney Markowitz, 1995)
ตอบกลับโพส
  • Similar Topics
    ตอบกลับ
    แสดง
    โพสต์ล่าสุด

ผู้ใช้งานขณะนี้

สมาชิกกำลังดูบอร์ดนี้: Bing [Bot], Itadm และบุคลทั่วไป 72