2017-06-13 43 views
0

繼Joomla創建自定義組件的文檔,並搜索論壇後,我創建了幾個帶有菜單鏈接的管理視圖,並且一切正常。當我嘗試編輯任何視圖中的項目時,就會出現中斷。編輯頁面始終是默認的HelloWorld消息表單。只爲S & G我做了一個查找和替換所有helloworld。沒有任何東西被破壞,表單仍然被重定向到默認的消息形式。這導致我相信我需要在表單標籤中包含一個& task =或其他東西,以便它知道在哪裏重定向。我是走在正確的軌道上嗎,還是我如此出軌以致於無所不能?自定義joomla組件的多個編輯表單

乾杯!

P.S.我注意到,當我選擇的元素在視圖編輯/ elements.php它現在已經與它相關聯的&任務= element.edit,但似乎仍然調用默認HelloWorld.messages

對不起差縮進。它沒有拷貝過來好

管理/視圖/元素/ TMPL /如default.php

<?php 
/** 
* @package  Joomla.Administrator 
* @subpackage com_chimera 
* @author  Chimera.Zen <[email protected]> 
* @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> 

admin/models/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; 
    } 
} 
+0

你能不能顯示你的代碼 –

+0

我可能忘記了包含一個文件,所以如果有其他需要的東西,我也會把它們取出來。謝謝! –

+0

我想我已經縮小到不加載表單的正確數據。它正在加載正確的edit.php,但表單是錯誤的。 –

回答