自定义joomla组件的多个编辑表单

时间:2017-06-13 15:03:01

标签: php joomla

按照Joomla上的文档创建自定义组件,并在论坛中搜索,我创建了几个带有菜单链接的管理员视图等,一切正常。当我尝试在任何视图中编辑项目时,就会出现中断。编辑页面始终是默认的HelloWorld消息表单。仅为S& G我在所有helloworld上找到并替换。没有任何损坏,表单仍然重定向到默认消息表单。这让我相信我需要在表单标记中包含一个& task =或者某些东西,以便它知道重定向的位置。我是在正确的轨道上还是我如此出轨以至于守车正在领先?

干杯!

P.S。我注意到当我在views / elements.php中选择要编辑的元素时,它现在有一个与它关联的& task = element.edit,但似乎仍然在调用默认的HelloWorld.messages

抱歉压痕很差。它没有很好地复制

管理员/视图/元件/ TMPL /如default.php

<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_chimera
 * @author      Chimera.Zen <chimera.zen@gmail.com>
 * @copyright   Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 * @version         v1.0.5
 */

// No direct access to this file
defined('_JEXEC') or die('Restricted Access');
?>
 <form action="index.php?option=com_chimera&view=elements" method="post" id="adminForm" name="adminForm">
  <table class="table table-striped table-hover">
    <thead>
    <tr>
        <th width="1%"><?php echo JText::_('COM_CHIMERA_NUM'); ?></th>
        <th width="2%">
            <?php echo JHtml::_('grid.checkall'); ?>
        </th>
        <th width="10%">
            <?php echo JText::_('COM_CHIMERA_ELEMENT_NAME') ;?>
        </th>
        <th width="10%">
            <?php echo JText::_('COM_CHIMERA_ELEMENT_GROUP') ;?>
        </th>
        <th width="50%">
            <?php echo JText::_('COM_CHIMERA_ELEMENT_ATTRIBUTES') ;?>
        </th>
        <th width="5%">
            <?php echo JText::_('COM_CHIMERA_PUBLISHED'); ?>
        </th>
        <th width="2%">
            <?php echo JText::_('COM_CHIMERA_ID'); ?>
        </th>
    </tr>
    </thead>
    <tbody>
        <?php if (!empty($this->items)) : ?>
            <?php foreach ($this->items as $i => $row) :
                $link = JRoute::_('index.php?option=com_chimera&task=element.edit&id=' . $row->id);
            ?>
                <tr>
                    <td><?php echo $this->pagination->getRowOffset($i); ?></td>
                    <td>
                        <?php echo JHtml::_('grid.id', $i, $row->id); ?>
                    </td>
                    <td>
                        <a href="<?php echo $link; ?>" title="<?php echo JText::_('COM_CHIMERA_EDIT_ELEMENT'); ?>">
                            <?php echo $row->element; ?>
                        </a>
                    </td>
                    <td>
                            <?php echo $row->element_group; ?>
                    </td>
                    <td> <?php
            $attributes = '<ul>';
            foreach($row->attributes as $attribute){
              $href = JRoute::_('index.php?option=com_chimera&view=attributes#'.$attribute["name"]);
              $attributes .= '<li><a href="'.$href.'">'.$attribute["name"];
              if($attribute["global"] == "1"){
                $attributes .= '<i class="global fa fa-globe" aria-hidden="true" title="Global Attribute"></i>';
              }
              $attributes .= '</a></li>';
            }
            $attributes .= '</ul>';
            echo $attributes;?>
                    </td>
                    <td align="center">
                        <?php echo JHtml::_('jgrid.published', $row->published, $i, 'elements.', true, 'cb'); ?>
                    </td>
                    <td align="center">
                        <?php echo $row->id; ?>
                    </td>
                </tr>
            <?php endforeach; ?>
        <?php endif; ?>
    </tbody>
    <tfoot>
        <tr>
            <td colspan="5">
                <?php echo $this->pagination->getListFooter(); ?>
            </td>
        </tr>
    </tfoot>
</table>
<input type="hidden" name="task" value=""/>
<input type="hidden" name="boxchecked" value="0"/>
<?php echo JHtml::_('form.token'); ?>

管理员/视图/元件/ TMPL / edit.php

<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_chimera
 *
 * @copyright   Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

// No direct access
defined('_JEXEC') or die('Restricted access');
JHtml::_('behavior.formvalidation');
?>
<form action="<?php echo JRoute::_('index.php?option=com_chimera&layout=edit&id=' . (int) $this->item->id); ?>"
    method="post" name="adminForm" id="adminForm" class="form-validate">
    <div class="form-horizontal">
        <?php echo JHtml::_('bootstrap.startTabSet', 'myTab', array('active' => 'details')); ?>

        <?php echo JHtml::_('bootstrap.addTab', 'myTab', 'details', JText::_('COM_CHIMERA_CHIMERA_DETAILS')); ?>
        <div class="row-fluid">
            <div class="span9">
          <div>
                <?php
                echo $this->form->renderFieldset('details');
                ?>
        </div>
                <div id="image">
                <?php echo $this->form->renderFieldset('params'); ?>
                </div>
            </div>
            <div class="span3">
                <?php echo JLayoutHelper::render('joomla.edit.global', $this); ?>
            </div>
        </div>
        <?php echo JHtml::_('bootstrap.endTab'); ?>

        <?php echo JHtml::_('bootstrap.addTab', 'myTab', 'accesscontrol', JText::_('COM_CHIMERA_FIELDSET_RULES')); ?>
        <div class="row-fluid form-horizontal-desktop">
            <div class="span12">
                <?php echo $this->form->renderFieldset('accesscontrol'); ?>
            </div>
        </div>
        <?php echo JHtml::_('bootstrap.endTab'); ?>

        <?php echo JHtml::_('bootstrap.endTabSet'); ?>
    </div>
    <input type="hidden" name="task" value="element.edit" />
    <?php echo JHtml::_('form.token'); ?>
</form>

管理员/模型/ element.php

<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_chimera
 *
 * @copyright   Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

// No direct access
defined('_JEXEC') or die('Restricted access');
JHtml::_('behavior.formvalidation');
?>
<form action="<?php echo JRoute::_('index.php?option=com_chimera&layout=edit&id=' . (int) $this->item->id); ?>"
    method="post" name="adminForm" id="adminForm" class="form-validate">
    <div class="form-horizontal">
        <?php echo JHtml::_('bootstrap.startTabSet', 'myTab', array('active' => 'details')); ?>

        <?php echo JHtml::_('bootstrap.addTab', 'myTab', 'details', JText::_('COM_CHIMERA_CHIMERA_DETAILS')); ?>
        <div class="row-fluid">
            <div class="span9">
          <div>
                <?php
                echo $this->form->renderFieldset('details');
                ?>
        </div>
                <div id="image">
                <?php echo $this->form->renderFieldset('params'); ?>
                </div>
            </div>
            <div class="span3">
                <?php echo JLayoutHelper::render('joomla.edit.global', $this); ?>
            </div>
        </div>
        <?php echo JHtml::_('bootstrap.endTab'); ?>

        <?php echo JHtml::_('bootstrap.addTab', 'myTab', 'accesscontrol', JText::_('COM_CHIMERA_FIELDSET_RULES')); ?>
        <div class="row-fluid form-horizontal-desktop">
            <div class="span12">
                <?php echo $this->form->renderFieldset('accesscontrol'); ?>
            </div>
        </div>
        <?php echo JHtml::_('bootstrap.endTab'); ?>

        <?php echo JHtml::_('bootstrap.endTabSet'); ?>
    </div>
    <input type="hidden" name="task" value="element.edit" />
    <?php echo JHtml::_('form.token'); ?>
</form>

管理员/表/ element.php

<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_chimera
 *
 * @copyright   Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */
// No direct access
defined('_JEXEC') or die('Restricted access');

/**
 * Hello Table class
 *
 * @since  0.0.1
 */
class ChimeraTableElement extends JTable
{
    /**
     * Constructor
     *
     * @param   JDatabaseDriver  &$db  A database connector object
     */
    function __construct(&$db)
    {
        parent::__construct('#__html_attributes', 'id', $db);
    }
    /**
     * Overloaded bind function
     *
     * @param       array           named array
     * @return      null|string     null is operation was satisfactory, otherwise returns an error
     * @see JTable:bind
     * @since 1.5
     */
    public function bind($array, $ignore = '')
    {
        if (isset($array['params']) && is_array($array['params']))
        {
            // Convert the params field to a string.
            $parameter = new JRegistry;
            $parameter->loadArray($array['params']);
            $array['params'] = (string)$parameter;
        }

        // Bind the rules.
        if (isset($array['rules']) && is_array($array['rules']))
        {
            $rules = new JAccessRules($array['rules']);
            $this->setRules($rules);
        }

        return parent::bind($array, $ignore);
    }

    /**
     * Overloaded load function
     *
     * @param       int $pk primary key
     * @param       boolean $reset reset data
     * @return      boolean
     * @see JTable:load
     */
    public function load($pk = null, $reset = true)
    {
        if (parent::load($pk, $reset))
        {
            // Convert the params field to a registry.
            $params = new JRegistry;
            $params->loadString($this->params, 'JSON');

            $this->params = $params;
            return true;
        }
        else
        {
            return false;
        }
    }
    /**
     * Method to compute the default name of the asset.
     * The default name is in the form `table_name.id`
     * where id is the value of the primary key of the table.
     *
     * @return  string
     * @since   2.5
     */
    protected function _getAssetName()
    {
        $k = $this->_tbl_key;
        return 'com_chimera.element.'.(int) $this->$k;
    }
    /**
     * Method to return the title to use for the asset table.
     *
     * @return  string
     * @since   2.5
     */
    protected function _getAssetTitle()
    {
        return $this->element;
    }
    /**
     * Method to get the asset-parent-id of the item
     *
     * @return  int
     */
    protected function _getAssetParentId(JTable $table = NULL, $id = NULL)
    {
        // We will retrieve the parent-asset from the Asset-table
        $assetParent = JTable::getInstance('Asset');
        // Default: if no asset-parent can be found we take the global asset
        $assetParentId = $assetParent->getRootId();

        // Find the parent-asset
        if (($this->catid)&& !empty($this->catid))
        {
            // The item has a category as asset-parent
            $assetParent->loadByName('com_chimera.category.' . (int) $this->catid);
        }
        else
        {
            // The item has the component as asset-parent
            $assetParent->loadByName('com_chimera');
        }

        // Return the found asset-parent-id
        if ($assetParent->id)
        {
            $assetParentId=$assetParent->id;
        }
        return $assetParentId;
    }
}

1 个答案:

答案 0 :(得分:1)

经过多次搜索,我发现这个帖子JForm::getInstance could not load file已经解决了我的问题。

长话短说:XML文件损坏。