ถามตอบ ปัญหาการพัฒนา Extension ไม่ว่าจะเป็น Module plugin Component หรือ แม้แต่ template การปรับแต่งโค้ด Joomla ต่างๆ ทุกเวอร์ชั่น 1.5 2.5 หรือ 3.x
Moderator: mindphp , ผู้ดูแลกระดาน
pprn
PHP Super Hero Member
โพสต์: 565 ลงทะเบียนเมื่อ: 02/07/2018 10:45 am
โพสต์ที่ยังไม่ได้อ่าน
โดย pprn » 02/10/2018 10:36 pm
ต้องการสร้างปุ่มลบค่าในตารางจาก Database ใน component ใน Joomla 3.8.11 ดังรูป
โดยปุ่ม 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
ดังรูป
ตัวอย่างโค้ด ไฟล์ 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
โพสต์: 565 ลงทะเบียนเมื่อ: 02/07/2018 10:45 am
โพสต์ที่ยังไม่ได้อ่าน
โดย pprn » 02/10/2018 11:17 pm
ได้แล้วค่ะ
ต้อง สร้างฟังก์ชั่น 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);
}
}
0 ตอบกลับ
3226 แสดง
โพสต์ล่าสุด โดย Four
09/01/2018 4:23 pm
สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 94