ไม่สามารถสร้างปุ่มลบค่าจาก Database ใน Component ได้ค่ะ

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

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

ภาพประจำตัวสมาชิก
pprn
PHP Super Hero Member
PHP Super Hero Member
โพสต์: 565
ลงทะเบียนเมื่อ: 02/07/2018 10:45 am

ไม่สามารถสร้างปุ่มลบค่าจาก Database ใน Component ได้ค่ะ

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

ต้องการสร้างปุ่มลบค่าในตารางจาก Database ใน component ใน Joomla 3.8.11 ดังรูป
  • errr.jpg
โดยปุ่ม New และ Edit ใช้ได้ปกติค่ะ

แต่ขึ้น error ว่า

An error has occurred.
0 Call to a member function delete() on boolean
D:\xampp\htdocs\joomla_***\libraries\src\MVC\Controller\AdminController.php:132

ดังรูป
  • err.jpg
ตัวอย่างโค้ด ไฟล์ view.html.php ในไฟล์ customeritems > models
  • โค้ด: เลือกทั้งหมด

    <?php
    /**
     * @package     com_customer
     * @author      Mindphp Devoloper
     *
     * @copyright   Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
     * @license     GNU General Public License version 2 or later; see LICENSE.txt
     */
    
    // ป้องกันไม่ให้เรียกใช้งานโดยตรง ต้องเปิดผ่าน joomla 
    defined('_JEXEC') or die;
    
    class CustomerViewCustomerItems extends JViewLegacy 
    {
        public function display($tpl = null) 
        {
           
            $this->items = $this->get('Items');
            $this->state = $this->get('State');
            $this->pagination = $this->get('Pagination');
            $this->filterForm    = $this->get('FilterForm');
    	$this->activeFilters = $this->get('ActiveFilters');
            
            $this->addToolBar();
            parent::display($tpl);
        }
        
        public function addToolBar()
        {
                JToolbarHelper::title(JText::_('COM_CUSTOMER'));
                
                JToolbarHelper::addNew('customeritem.add');
                JToolbarHelper::editList('customeritem.edit');
                JToolbarHelper::deleteList('', 'customeritems.delete');
        }
    }
มีวิธีแก้ยังไงบ้างค่ะ
ภาพประจำตัวสมาชิก
pprn
PHP Super Hero Member
PHP Super Hero Member
โพสต์: 565
ลงทะเบียนเมื่อ: 02/07/2018 10:45 am

Re: ไม่สามารถสร้างปุ่มลบค่าจาก Database ใน Component ได้ค่ะ

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

ได้แล้วค่ะ
ต้อง สร้างฟังก์ชั่น function getModel ขึ้นมาใน ไฟล์ customeritems.php ในโฟลเดอร์ controller

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

<?php
/**
 * @package     com_customer
 * @author      Mindphp Devoloper
 *
 * @copyright   Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

// ป้องกันไม่ให้เรียกใช้งานโดยตรง ต้องเปิดผ่าน joomla 
defined('_JEXEC') or die;


class  CustomerControllerCustomerItems extends Joomla\CMS\MVC\Controller\AdminController
{
    public function getModel($name = 'CustomerItem', $prefix = '', $config = array())
	{
		return parent::getModel($name, $prefix, $config);
	}
}
ตอบกลับโพส
  • Similar Topics
    ตอบกลับ
    แสดง
    โพสต์ล่าสุด

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

สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 93