【发布时间】:2014-08-17 08:45:50
【问题描述】:
我正在为 Joomla 开发一个 MVC 组件! 2.5,我想在我的后端添加一些可排序的列。为了这个目标,我尝试了下一个:
http://docs.joomla.org/Adding_sortable_columns_to_a_table_in_a_component
我收到一个错误“未找到视图 [名称、类型、前缀]”。在这种情况下,我一直在寻找解决方案,我找到了下一个:
http://forum.joomla.org/viewtopic.php?p=2638695
根据这些指示,我删除了我的“表单”的“动作”。在这种情况下,我的列是可排序的,但出现了另一个问题。如果我删除“表单”的“操作”,那么工具栏的“编辑按钮”将不起作用。
我认为必须有另一种解决方案,因为我还需要工作“编辑按钮”和可排序的列。我在这里寻找一些类似的问题,并应用了以下信息:
How to add sortable columns in a Joomla component (table), both ASC and DESC with an arrow
&
Joomla 2.5 -Adding sortable columns to a table in a component
但我的问题仍然存在。我能做些什么??谢谢。
下一个是我的相关源代码:
com_inscripciones/admin/models/anuals.php
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// import the Joomla modellist library
jimport('joomla.application.component.modellist');
/**
* Inscripciones List Model
*/
class InscripcionesModelAnuals extends JModelList
{
public function __construct($config = array())
{
if (empty($config['filter_fields'])) {
$config['filter_fields'] = array(
'nombre',
'fecha_nac',
'reserva'
);
}
parent::__construct($config);
}
protected function populateState($ordering = null, $direction = null)
{
parent::populateState('id', 'asc');
}
/**
* Method to build an SQL query to load the list data.
*
* @return string An SQL query
*/
protected function getListQuery()
{
// Create a new query object.
$db = JFactory::getDBO();
$query = $db->getQuery(true);
// Select some fields
$query->select('id,nombre,apellidos,nif,fecha_nac,reserva,validacion,clave');
// From the hello table
$query->from('#__anual');
// Add the list ordering clause.
$query->order($db->escape($this->getState('list.ordering', 'nombre')).' '.$db->escape($this->getState('list.direction', 'ASC')));
return $query;
}
}
?>
com_inscripciones/admin/views/anuals/view.html.php
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// import Joomla view library
jimport('joomla.application.component.view');
/**
* Anuals View
*/
class InscripcionesViewAnuals extends JView
{
/**
* display method of Inscripciones view
* @return void
*/
function display($tpl = null)
{
// Get data from the model
$items = $this->get('Items');
$pagination = $this->get('Pagination');
$state = $this->get('State');
$this->sortDirection = $state->get('list.direction');
$this->sortColumn = $state->get('list.ordering');
// Check for errors.
if (count($errors = $this->get('Errors')))
{
JError::raiseError(500, implode('<br />', $errors));
return false;
}
// Assign data to the view
$this->items = $items;
$this->pagination = $pagination;
// Set the toolbar
$this->addToolBar();
// Display the template
parent::display($tpl);
}
/**
* Setting the toolbar
*/
protected function addToolBar()
{
JToolBarHelper::title(JText::_('Inscripciones Manager: Curso Anual'), 'inscripciones');
JToolBarHelper::spacer('10');
JToolBarHelper::divider();
JToolBarHelper::spacer('10');
JToolBarHelper::editList('anual.edit');
JToolBarHelper::spacer('10');
JToolBarHelper::divider();
JToolBarHelper::spacer('10');
JToolBarHelper::deleteList('¿Desea eliminar esta inscripción?', 'anuals.delete');
JToolBarHelper::spacer('20');
}
}
?>
com_inscripciones/admin/views/anuals/tmpl/default.php
<?php
// No direct access
defined('_JEXEC') or die('Restricted access');
JHtml::_('behavior.tooltip');
JHtml::_('behavior.multiselect');
?>
<form action="<?php echo JRoute::_('index.php?option=com_inscripciones&view=anuals$layout=default'); ?>"method="post" name="adminForm"id="inscripciones-form">
<table class="adminlist">
<thead>
<tr>
<th width="5">
<?php echo JText::_('ID'); ?>
</th>
<th width="20">
<input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count($this->items); ?>);" />
</th>
<th>
<?php echo JHtml::_('grid.sort', 'NOMBRE', 'nombre', $this->sortDirection, $this->sortColumn); ?>
</th>
<th>
<?php echo JText::_('APELLIDOS'); ?>
</th>
<th>
<?php echo JText::_('NIF'); ?>
</th>
<th>
<?php echo JHtml::_('grid.sort', 'FECHA NAC.', 'fecha_nac', $this->sortDirection, $this->sortColumn); ?>
</th>
<th>
<?php echo JHtml::_('grid.sort', 'RESERVA', 'reserva', $this->sortDirection, $this->sortColumn); ?>
</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="3"></td>
</tr>
</tfoot>
<tbody>
<?php foreach ($this->items as $i => $item): ?>
<tr class="row<?php echo $i % 2; ?>">
<td>
<?php echo $item->id; ?>
</td>
<td>
<?php echo JHtml::_('grid.id', $i, $item->id); ?>
</td>
<td>
<?php echo $item->nombre; ?>
</td>
<td>
<?php echo $item->apellidos; ?>
</td>
<td>
<?php echo $item->nif; ?>
</td>
<td>
<?php echo $item->fecha_nac; ?>
</td>
<td>
<?php echo $item->reserva; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<div>
<input type="hidden" name="task" value="" />
<input type="hidden" name="boxchecked" value="0" />
<input type="hidden" name="filter_order" value="<?php echo $this->sortColumn; ?>" />
<input type="hidden" name="filter_order_Dir" value="<?php echo $this->sortDirection; ?>" />
<?php echo JHtml::_('form.token'); ?>
</div>
【问题讨论】:
-
请提供相关源代码,否则只能猜测是什么问题。
-
OKEY。添加了相关的源代码。谢谢。
-
尝试删除
$query->order($db->escape($this->getState('list.ordering', 'nombre')).' '.$db->escape($this->getState('list.direction', 'ASC')));中的nombre和ASC -
感谢您的回复,但不幸的是我的问题仍然存在。