สอบถาม Component ในหน้า Customers กด New แล้วไปหน้าฟอร์มไม่ได้

ถามตอบ ปัญหาการพัฒนา 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

สอบถาม Component ในหน้า Customers กด New แล้วไปหน้าฟอร์มไม่ได้

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

สอบถามในหน้า Customers กด New แล้วไปหน้าฟอร์มไม่ได้ครับ ขึ้น error แทน กำลังฝึกทำ Component อยู่ครับ
An error has occurred.
0 Class "Joomla\CMS\MVC\Controller\FromController" not found
หน้า Customers ไปกดที่ New
Joomla Development-1.png
Joomla Development-1.png (82.23 KiB) Viewed 1323 times
ขึ้น error แทนครับ
Joomla Development-2.png
Joomla Development-2.png (15.36 KiB) Viewed 1323 times
โค้ด models -> customer.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 MExampleModelCustomer extends \Joomla\CMS\MVC\Model\AdminModel
{
    public function getForm($data = array(), $loadData = true)
	{
		return $this->loadForm('com_mexample.customer', 'customer', array('control' => 'jform', 'load_data' => $loadData));

	}

	public function getTable($name = 'Customer', $prefix = 'MExampleTable', $options = array())
	{
		return parent::getTable($name, $prefix, $options);

	}
}
models -> forms -> customer.xml

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

<?xml version="1.0" encoding="utf-8"?>
<form>
    <fieldset name="detail">
        <field
                name="name"
                type="text"
                label="COM_MEXAMPLE_NAME"
                description="COM_MEXAMPLE_NAME_DECS"
                required="true"
        />
        <field
                name="birthday"
                type="calendar"
                label="COM_MEXAMPLE_BIRTHDAY"
                description="COM_MEXAMPLE_BIRTHDAY_DECS"
                required="true"
        />
        <field
                name="gender"
                type="radio"
                label="COM_MEXAMPLE_GENDER"
                description="COM_MEXAMPLE_GENDER_DECS"
                default="1"
                >
                <option value="1">COM_MEXAMPLE_MALE</option>
                <option value="2">COM_MEXAMPLE_FEMLE</option>
        </field> 
        <field
                name="age"
                type="text"
                label="COM_MEXAMPLE_AGE"
                description="COM_MEXAMPLE_AGE_DECS"
                required="true"
        />    
        <field
                name="address"
                type="textarea"
                label="COM_MEXAMPLE_ADDRESS"
                description="COM_MEXAMPLE_ADDRESS_DECS"
                required="true"
        /> 
        <field
                name="phone"
                type="text"
                label="COM_MEXAMPLE_PHONE"
                description="COM_MEXAMPLE_PHONE_DECS"
        />
        <field
                name="image"
                type="file"
                label="COM_MEXAMPLE_IMAGE"
                description="COM_MEXAMPLE_IMAGE_DECS"
        />  
        <field
                name="id"
                type="hidden"
        />            
    </fieldset>
</form>

views -> customer -> 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 MExampleViewCustomer extends Joomla\CMS\MVC\View\HtmlView
{
    public function display($tpl = null)
    {
        $this->item = $this->get('Item');
		$this->form = $this->get('Form');
		$this->state = $this->get('State');

        $this->addToolbar();
        parent::display($tpl);
    }

    public function addToolbar()
    {
        \Joomla\CMS\Toolbar\ToolbarHelper::title(JText::_('COM_MEXAMPLE_CUSTOMER_FORM'));

        \Joomla\CMS\Toolbar\ToolbarHelper::apply('customer.apply');
        \Joomla\CMS\Toolbar\ToolbarHelper::save('customer.save');
        \Joomla\CMS\Toolbar\ToolbarHelper::save2new('customer.save2new');
        \Joomla\CMS\Toolbar\ToolbarHelper::save2copy('customer.save2copy');
        \Joomla\CMS\Toolbar\ToolbarHelper::cancel('customer.cancel');

        \Joomla\CMS\Toolbar\ToolbarHelper::preferences('com_mexample');
    }
}
views -> customer ->tmpl -> edit.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;

JHtml::_('behavior.formvalidator');
JHtml::_('behavior.keepalive');
JHtml::_('formbehavior.chosen', 'select');

JFactory::getDocument()->addScriptDeclaration("
	Joomla.submitbutton = function(task)
	{
		if (task == 'tag.cancel' || document.formvalidator.isValid(document.getElementById('item-form'))) {
			Joomla.submitform(task, document.getElementById('item-form'));
		}
	};
");
?>
<form action="<?php echo JRoute::_('index.php?option=com_mexample&layout=edit&id=' . (int) $this->item->id); ?>" method="post" name="item-form" id="item-form" class="form-horizontal">
    <fieldset>
        <?php foreach ($this->form->getFieldset('detail') as $field): ?>
            <div class="control-group">
                <div class="control-label">
                    <?php echo $field->label; ?>
                </div>
                <div class="controls">
                    <?php echo $field->input; ?>
                </div>
            </div>
        <?php endforeach; ?>
    </fieldset>
</form>
:gfb:
ภาพประจำตัวสมาชิก
tsukasaz
PHP VIP Members
PHP VIP Members
โพสต์: 21989
ลงทะเบียนเมื่อ: 18/04/2012 9:39 am

Re: สอบถาม Component ในหน้า Customers กด New แล้วไม่ไปหน้าแก้ไข

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

มันน่าจะ error ที่ไฟล์ customer.php ในโฟลเดอร์ controllers ที่ไม่ได้แปะมาในโพส

ชื่อ class ของไฟล์นั้นผิด ต้องเขียนว่า Form ไม่ใช่ From ครับ
The last bug isn't fixed until the last user is dead. (Sidney Markowitz, 1995)
ตอบกลับโพส
  • Similar Topics
    ตอบกลับ
    แสดง
    โพสต์ล่าสุด

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

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