Joomla,从 edit.php 的自定义输入字段保存日期,没有表单 xml 文件

Joomla, Save Date from custom input fields from the edit.php without a form xml file

我是 joomla 的新手,目前我编写了一个组件,您可以在其中对项目进行评分和评论。 对于评论我只需要一个文件,编辑一个和他的控制器,这应该只有一个自定义输入字段而不使用 XML 表单文件并且没有他的默认视图的复数文件。 问题是我还没有找到如何使用 jomla 保存按钮将我的数据保存到数据库中。当我保存我的数据时,我被重定向到一个新站点并且数据没有通过 post 发送。我只能在我的控制器文件中使用 save() 函数来显示消息,但我无法显示任何 post 输入。

这也是我的代码。我觉得,少了点什么。

我的控制器文件comments.php

class EasyratingControllerComments extends JControllerAdmin
 {
    public function getModel($name = 'Comments', $prefix = 'EasyratingModel', $config = array('ignore_request' => true))
    {
        $model = parent::getModel($name, $prefix, $config);
        return $model;
    }
}

我的模型文件comments.php

class EasyratingModelComments extends JModelList
{
    public function __construct($config = array())
    {
        if (empty($config['filter_fields']))
        {
            $config['filter_fields'] = array(
                'id', 'a.id',
                'rating_id', 'a.rating_id',
                'comments', 'a.comments',
            );
        }
            parent::__construct($config);
    }

    protected function populateState($ordering = null, $direction = null)
    {
        $id = JRequest::getInt('id');
        $this->setState('id', $id);
    }

    public function getTable($type = 'Easyrating_comments', $prefix = 'EasyratingTable', $config = array())
    {
        return JTable::getInstance($type, $prefix, $config);
    }

    protected function getListQuery()
    {
        $db = $this->getDbo();
        $query = $db->getQuery(true);
        $query->select(
        $this->getState(
                'list.select',
                'a.id,'a.rating_id, a.comments, a.created_by' 
        )
        );

            $query->from($db->quoteName('#__easyrating_comments').' AS a');
            $query->where('(a.state IN (0, 1))');

        if ($id = $this->getState('id'))
        {
            $query->where('a.rating_id = '.(int) $id);
        }

            return $query;
    }
}

我的档案view.html.php

class EasyratingViewComments extends JViewLegacy
{
protected $items;
protected $state;
protected $pagination;

public function display($tpl = null)
{
            $this->items        = $this->get('Items');
            $this->state        = $this->get('State');
            $this->pagination   = $this->get('Pagination');
            $app = JFactory::getApplication();
            $params = $app->getParams();
            $this->assignRef('params', $params);
    parent::display($tpl);
}

我的文件edit.php(不是全部只有重要的部分)

<form action="<?php echo JRoute::_('index.php?option=com_easyrating&view=comments&layout=edit&id='.(int) $ratingID); ?>"method="post" name="adminForm" id="adminForm" class="col col-md-12 rating-comments-main-input-field text-center form-validate comments">
                        <fieldset>
        <textarea name="jform[comments]" id="jform_comments" class="rating-comments-main-textarea" cols="50" rows="30"></textarea>
        <button type="button" class="btn btn-success" style="margin-right: 15px;" onclick="Joomla.submitbutton('comments.save')">                       <i class="icon-new"></i> <?php echo JText::_('JSAVE')?>                             </button>
        <input type="hidden" name="task" value="" />
        <?php echo JHtml::_('form.token'); ?>
        <?php echo JHtml::_('bootstrap.endPane'); ?>
                        </fieldset>
</form>

提交表单时调用控制器函数comments.save。我猜你没有 save() - 你的控制器中的函数,这是由默认方法处理的,它使用 xml 文件格式来验证(你没有)。要覆盖我认为你的控制器应该在一个名为 com_easyrating/controllers/comments.php

的文件中
class EasyRatingControllerComments{
  function save(){ 
    // here you should be able to handle your input
  }
} 

我认为要使用内置的 joomla 功能,您需要定义一个 xml-file。我不明白你为什么不?这是处理表单输入的标准 Joomla 方式。在 docs.joomla.org/...

查看一些文档

获得组件框架的一种简单方法是最初使用组件创建器,f.ex。 component-creator.com