Joomla 组件工具栏按钮不起作用
Posted
技术标签:
【中文标题】Joomla 组件工具栏按钮不起作用【英文标题】:Joomla Component Tool Bar Buttons Not Working 【发布时间】:2014-07-26 18:54:20 【问题描述】:我正在构建一个 Joomla 组件并尝试使用 Joomla 工具栏,问题是按钮无法正常工作,至少发布和取消发布按钮不是(编辑) - 当我使用工具中的发布或取消发布按钮时栏,页面重新加载,它给出了成功消息但状态保持不变。
这是我的代码:
表格文件
<?php
defined( '_JEXEC' ) or die("Restricted Access");
class WetvprogramschedulerTableDay extends JTable
public function __construct(&$db)
parent::__construct('#__wetv_programs_days', 'program_day_id', $db);
?>
单记录模型
<?php
defined( '_JEXEC' ) or die("Restricted Access");
jimport('joomla.application.component.modeladmin');
class WetvprogramschedulerModelDay extends JModelAdmin
public function getTable($type = 'Day', $prefix = 'WetvprogramschedulerTable', $config = array())
return JTable::getInstance($type, $prefix, $config);
public function getForm($data = array(), $loadData = true)
$form = $this->loadForm();
return $form;
?>
编辑
列表模型
<?php
defined( '_JEXEC' ) or die("Restricted Access");
jimport('joomla.application.component.modellist');
class WetvprogramschedulerModelDays extends JModelList
public function __construct($config = array())
if (empty($config['filter_fields']))
$config['filter_fields'] = array(
'program_day',
'program_day_image',
'published'
);
parent::__construct($config);
public function getItems()
// Run the query returned from getListQuery()
$items = parent::getItems();
// Prepare urls for View
// Doing this means we don't have to do it in the view
foreach ($items as &$item)
$item->url = 'index.php?option=com_wetvprogramscheduler&task=day.edit&program_day_id=' . $item->program_day_id;
return $items;
public function getListQuery()
$query = parent::getListQuery();
$query->select('*');
$query->from('#__wetv_programs_days');
// use state obtained from populateState()
$published = $this->getState('filter.published');
if ($published == '')
$query->where('(published = 1 OR published = 0)');
else if ($published != '*')
$published = (int) $published;
$query->where("(published = '$published')");
$search = $this->getState('filter.search');
$db = $this->getDbo();
if (!empty($search))
$search = '%' . $db->getEscaped($search, true) . '%';
$field_searches =
"(program_day_image LIKE '$search' OR " .
"program_day LIKE '$search')";
$query->where($field_searches);
// Column ordering
$orderCol = $this->getState('list.ordering');
$orderDirn = $this->getState('list.direction');
if ($orderCol != '')
$query->order($db->getEscaped($orderCol.' '.$orderDirn));
return $query;
protected function populateState($ordering = null, $direction = null)
$search = $this->getUserStateFromRequest($this->context.'.filter.search', 'filter_search');
$this->setState('filter.search', $search);
/*
*Check both both session and form variable to see if
*There is a value for the filter_published variable
*/
$published = $this->getUserStateFromRequest($this->context.'.filter.published', 'filter_published');
// If filter_published value, set it in model state.
//so we can get value when we get state.
$this->setState('filter.published', $published);
parent::populateState($ordering, $direction);
?>
控制器
<?php
defined( '_JEXEC' ) or die("Restricted Access");
jimport('joomla.application.component.controlleradmin');
class WetvprogramschedulerControllerDays extends JControllerAdmin
protected $text_prefix = 'COM_WETVPROGRAMSCHEDULER_DAYS';
public function getModel($name = 'Day', $prefix = 'WetvprogramschedulerModel', $config = array('ignore_request' => true))
$model = parent::getModel($name, $prefix, $config);
return $model;
?>
view.html.php
<?php
defined( '_JEXEC' ) or die("Restricted Access");
jimport( 'joomla.application.component.view');
class WetvprogramschedulerViewDays extends JView
protected $items;
protected $pagination;
public function display($tpl = null)
$this->items = $this->get('Items');
$this->pagination = $this->get('Pagination');
$this->addToolbar();
parent::display($tpl);
public function addToolbar()
JToolBarHelper::title(JText::_('COM_WETVPROGRAMSCHEDULER_DAYS_TITLE'));
JToolBarHelper::addNew('day.add');
JToolBarHelper::editList('day.edit');
JToolBarHelper::divider();
JToolBarHelper::publishList('days.publish');
JToolBarHelper::unpublishList('days.unpublish');
JToolBarHelper::divider();
JToolBarHelper::archiveList('days.archive');
JToolBarHelper::trash('days.trash');
?>
default.php
<?php defined( '_JEXEC' ) or die("Restricted Access"); ?>
<form action="index.php?option=com_wetvprogramscheduler&view=days" method="post" name="adminForm" id="adminForm">
<table class="adminlist">
<thead>
<tr>
<th >
<input type="checkbox" name="checkall-toggle" value="" onclick="checkAll(this)" />
</th>
<th><?php echo JText::_('COM_WETVPROGRAMSCHEDULER_FIELD_DAY_NAME_LABEL') ?></th>
<th><?php echo JText::_('COM_WETVPROGRAMSCHEDULER_FIELD_DAY_IMAGE_LABEL') ?></th>
<th><?php echo JText::_('JSTATUS') ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($this->items as $i => $item): ?>
<tr class="row<?php echo $i % 2 ?>">
<td class="center">
<?php echo JHtml::_('grid.id', $i, $item->progam_day_id); ?>
</td>
<td>
<a href="<?php echo $item->url; ?>">
<?php echo $this->escape($item->program_day) ?></a>
</td>
<td><?php echo $this->escape($item->program_day_image) ?></td>
<td class="center">
<?php echo JHtml::_('jgrid.published',
$item->published, $i, 'days.', true, 'cb'); ?>
</td>
</tr>
<?php endforeach ?>
</tbody>
<tfoot>
<tr>
<td colspan="4">
<?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'); ?>
</form>
这是表的 sql 语句。
CREATE TABLE IF NOT EXISTS #__wetv_programs_days (
program_day_id BIGINT(20) NOT NULL AUTO_INCREMENT,
program_day VARCHAR(9) NOT NULL,
program_day_image VARCHAR(255) NOT NULL,
program_day_access int(11) DEFAULT '1',
program_day_alias varchar(255) DEFAULT NULL,
published tinyint(1) DEFAULT '0',
checked_out int(11) DEFAULT '0',
checked_out_time datetime DEFAULT '0000-00-00 00:00:00',
program_day_timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (program_day_id),
UNIQUE (program_day),
UNIQUE (program_day_alias)
);
【问题讨论】:
当您说“无法正常工作”时,究竟发生了什么?按钮没有响应还是页面重新加载但状态保持不变? 后者 - 页面重新加载但状态保持不变。 能否添加 mysql 表的create
语句,以便我们查看表的结构?
@cppl - 抱歉我回复晚了。我已经在问题中添加了声明。
我刚刚意识到你已经为WetvprogramschedulerModelDay
设置了模型,你可以为WetvprogramschedulerModelDays
设置模型
【参考方案1】:
复选框单元格中 default.php 的 progam_day_id 中缺少“r”。
应该是program_day_id
【讨论】:
以上是关于Joomla 组件工具栏按钮不起作用的主要内容,如果未能解决你的问题,请参考以下文章