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


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

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

这也是我的代码。我想,缺少一些东西。

我的控制器文件注释.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;
    }
}

我的模型文件评论.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;
    }
}

我的文件视图.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);
}

我的文件编辑.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 文件。我不明白你为什么不?使用这是处理表单输入的标准Joomla方法。在 docs.joomla.org/查看一些文档...

获取组件框架的一种简单方法是最初使用组件创建器,例如 component-creator.com