我的組件發生了致命錯誤。比方說,組件名稱是com_shirts,這是我的代碼 我的管理員/組件/ com_shirts /控制器/ code.php錯誤:調用成員函數getKeyName() - Joomla 2.5的組件
<?php
defined('_JEXEC') or die;
jimport('joomla.application.component.controllerform');
class ShirtsControllerCode extends JControllerForm{
protected $view_list = 'codes';
}
我的代碼在管理員/組件/ com_shirts /控制器/ 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 /模型/ 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 /模型/ 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&task=code.edit&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 /表/ code.php
<?php
defined('_JEXEC') or die;
class ShirtsTableCode extends JTable{
public function __construct(&$dbo){
parent::__construct('#__shirts_codes', 'code_id', $dbo);
}
}
我的代碼在管理員/組件/ com_shirts /視圖/代碼/ 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 /視圖/編碼/ TMPL /如default.php
<?php defined('_JEXEC') or die; ?>
<form action="index.php?option=com_shirts&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&view=code&task=code.edit&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 /視圖/代碼代碼/ TMPL/edit.php
<?php defined('_JEXEC') or die; ?>
<form
method="post"
name="adminForm"
class="form-validate"
action="index.php?option=com_shirts&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 /視圖/代碼/ 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"
我該如何解決這個問題?
你在哪裏得到的錯誤?什麼是視圖名稱?代碼或代碼? –
您可能需要再次檢查模型/表格,可能是某處存在某種類型,或者單數/數字之間不匹配。 –
@ValentinDespa,那是我遇到問題的地方。乾杯! – codinghands