3

我的组件出现致命错误。假设组件名称是 com_shirts,这是我的代码,我的代码在 administrator/component/com_shirts/controllers/code.php

<?php
defined('_JEXEC') or die;

jimport('joomla.application.component.controllerform');

class ShirtsControllerCode extends JControllerForm{
   protected $view_list = 'codes';
}

我在管理员/组件/com_shirts/controllers/codes.php 中的代码

<?php
defined('_JEXEC') or die;

jimport('joomla.application.component.controlleradmin');

class ShirtsControllerCodes extends JControllerAdmin{
   protected $text_prefix = 'COM_SHIRTS';

   function getModel($name='Code', $prefix='ShirtsModel', $config=array('ignore_request'=>TRUE)){
      $model = parent::getModel($name, $prefix, $config);

      return $model;
   }
}

我在管理员/组件/com_shirts/models/code.php 中的代码

<?php
defined('_JEXEC') or die;

jimport('joomla.application.component.modeladmin');

class ShirtsModelCode extends JModelAdmin{

   function getTable($type='Code', $prefix='ShirtsTable', $config=array()){
      return JTable::getInstance($type, $prefix, $config);
   }

   function getForm($data=array(), $loadData=TRUE){
      $form = $this->loadForm();

      return $form;
   }
}

我在管理员/组件/com_shirts/models/codes.php 中的代码

<?php
defined('_JEXEC') or die;

jimport('joomla.application.component.modellist');

class ShirtsModelCodes extends JModelList{

   function getItems(){
      $items = parent::getItems();

      foreach($items as &$item){
         $item->url = 'index.php?option=com_shirts&amp;task=code.edit&amp;code_id='.$item->code_id;
         $item->event_description = substr($item->code_desc, 0);
      }

      return $items;
   }

   function getListQuery(){
      $query = parent::getListQuery();

      $query->select('*');
      $query->from('#__shirts_codes');

      return $query;
   }
}

我在管理员/组件/com_shirts/tables/code.php 中的代码

<?php
defined('_JEXEC') or die;

class ShirtsTableCode extends JTable{

   public function __construct(&$dbo){
      parent::__construct('#__shirts_codes', 'code_id', $dbo);
   }
}

我在管理员/组件/com_shirts/views/codes/view.html.php 中的代码

<?php
defined('_JEXEC') or die;

jimport('joomla.application.component.view');

class ShirtsViewCodes extends JView{
   protected $codes;

   function display($tmpl=NULL){

      $this->codes = $this->get('Items');

      $this->toolbar();

      parent::display($tmpl);
   }

   function toolbar(){
      JToolBarHelper::title(JText::_('HEADER'));

      JToolBarHelper::addNew('code.add');
      JToolBarHelper::editList('code.edit');

      JToolBarHelper::divider();

      JToolBarHelper::publishList('codes.publish');
      JToolBarHelper::unpublishList('codes.unpublish');

      JToolBarHelper::divider();

      JToolBarHelper::archiveList('codes.archive');
      JToolBarHelper::trash('codes.trash');

      JToolBarHelper::divider();

   }
}

我在管理员/组件/com_shirts/views/codes/tmpl/default.php 中的代码

<?php defined('_JEXEC') or die; ?>

<form action="index.php?option=com_shirts&amp;view=codes" method="post" name="adminForm" id="adminForm">

   <table class="adminlist">
      <thead>
         <tr>
            <th style="width: 1%">
               <input type="checkbox" name="checkall-toggle" value="" onclick="checkAll(this)" />
            </th>
         </tr>
      </thead>
      <tbody>
         <?php foreach($this->codes as $i=>$code):
            $url = 'index.php?option=com_shirts&amp;view=code&amp;task=code.edit&amp;event_id='.$code->code_id;
         ?>
         <tr class="row<?php echo $i%2; ?>">
            <td class="center">
               <?php echo JHtml::_('grid.id', $i, $code->code_id); ?>
            </td>

            <td class="center">
               <a href="<?php echo $code->url; ?>">
                  <?php echo $this->escape($code->code); ?>
               </a>
            </td>

            <td>
               <a href="<?php echo $code->url; ?>">
                  <?php echo $this->escape($code->code_desc); ?>
               </a>
            </td>
         </tr>
         <?php endforeach; ?>
      </tbody>
   </table>

   <input type="hidden" name="task" value="" />
   <input type="hidden" name="boxchecked" value="0" />
   <?php echo JHtml::_('form.token'); ?>
</form>

我在管理员/组件/com_shirts/views/code/tmpl/edit.php 中的代码

<?php defined('_JEXEC') or die; ?>
<form
   method="post"
   name="adminForm"
   class="form-validate"
   action="index.php?option=com_shirts&amp;code_id=<?php echo $this->code->code_id; ?>"
>

   <div class="width-50 fltlft">
      <fieldset class="adminform">
         <ul class="adminformlist">
            <?php foreach($this->form->getFieldset('required') as $field): ?>
               <li>
                  <?php echo $field->label; ?>
                  <?php echo $field->input; ?>
               </li>
            <?php endforeach; ?>
      </fieldset>
   </div>

   <div class="width-40 fltrt">
      <fieldset class="adminform">
         <ul class="adminformlist">
            <?php foreach($this->form->getFieldset('optional') as $field): ?>
               <li>
                  <?php echo $field->label; ?>
                  <?php echo $field->input; ?>
               </li>
            <?php endforeach; ?>
         </ul>
      </fieldset>
   </div>
   <input type="hidden" name="task" value="" />
   <?php echo JHtml::_('form.token'); ?>
</form>

我在管理员/组件/com_shirts/views/code/view.html.php 中的代码

<?php
defined('_JEXEC') or die;

jimport('joomla.application.component.view');

class ShirtsViewCode extends JView{
   protected $code;
   protected $form;

   function display($tmpl=NULL){

      $this->event = $this->get('Item');
      $this->form = $this->get('Form');

      $this->toolbar();

      parent::display($tmpl);
   }

   function toolbar(){
      if($this->code->code_id){
         JToolBarHelper::title(JText::_('COM_SHIRTS_EDIT'));
      }else{
         JToolBarHelper::title(JText::_('COM_SHIRTS_ADD'));
      }

      JToolBarHelper::apply('code.apply', 'JTOOLBAR_APPLY');
      JToolBarHelper::save('code.save', 'JTOOLBAR_SAVE');
      JToolBarHelper::save2new('code.save', 'JTOOLBAR_SAVE_AND_NEW');

      JToolBarHelper::divider();

      JToolBarHelper::cancel('code.cancel');
   }
}

当我进入组件视图时,出现此错误

"PHP Fatal error: Call to a member function getKeyName() on a non-object in /var/www/joomla/libraries/joomla/application/component/controllerform.php on line 393"

我该如何解决?

4

1 回答 1

2

好的,那是我的错,我在 manifest.xml 中有错误,现在一切都很好

在清单中没有线

<folder>tables</folder>
于 2012-10-17T09:23:44.087 回答