Joomla组件工具栏按钮不起作用

问题描述 投票:-1回答:1

我正在构建一个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&amp;task=day.edit&amp;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&amp;view=days" method="post" name="adminForm" id="adminForm">
<table class="adminlist">
    <thead>
        <tr>
            <th width="1%">
                <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)
);
model-view-controller joomla components toolbar
1个回答
0
投票

缺少复选框单元格default.php中progam_day_id的“r”。

它应该是program_day_id

© www.soinside.com 2019 - 2024. All rights reserved.