I'm building a Joomla component and trying to use Joomla toolbars, problem is the buttons are not working properly, at least the publish and unpublish buttons are not (edit) - when I use the publish or unpublish button from the tool bar, the page reloads, it gives success message but the states remain the same.

Here's my code: (end edit)

The Table File

defined( '_JEXEC' ) or die("Restricted Access");

class WetvprogramschedulerTableDay extends JTable {
    public function __construct(&$db)
        parent::__construct('#__wetv_programs_days', 'program_day_id', $db);

The Model

defined( '_JEXEC' ) or die("Restricted Access");


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;

The Controller

defined( '_JEXEC' ) or die("Restricted Access");


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;


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');



    public function addToolbar() {








<?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">
            <th width="1%">
                <input type="checkbox" name="checkall-toggle" value="" onclick="checkAll(this)" />
            <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>
        <?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); ?>
                    <a href="<?php echo $item->url; ?>">
                    <?php echo $this->escape($item->program_day) ?></a>
                <td><?php echo $this->escape($item->program_day_image) ?></td>
                <td class="center">
                    <?php echo JHtml::_('jgrid.published',
                    $item->published, $i, 'days.', true, 'cb'); ?>
        <?php endforeach ?>
            <td colspan="4">
                <?php echo $this->pagination->getListFooter(); ?>

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

I would really appreciate a quick response. Thank you!


do you have a JModelList model? you need that for the listing view to properly display all the items. JModelAdmin is used for the individual edit views. You can look in a Joomla install in com_content That one has the best examples of how they work in my opinion (and simple as well). I say this too start just because I cannot see it in your examples. Not required but not having it can lead to other issues.

Your controller is correct just make sure for the edit view you use JControllerForm To use Joomla's xml based settings and such (more of that can be found in the documentation).


This link has some excellent examples of the basic structure.

The main thing to make sure these basic functions operate as intended is to ensure that the standard Joomla structure is followed as closely as possible.

You will also notice that in most cases Joomla uses "state" and not "published" for the actual database column.

<?php echo JHtml::_('jgrid.published',
                    $item->state, $i, 'days.', true, 'cb'); ?>

would work better as a lot of the classes in Joomla assume "state" rather then "published" so although its easy to pull from a published column, editing it may not be as easy.

Also if you are getting any specific error that can help isolate the issue as well, this answer is indirect as the question is not specific. It will be updated if more information is given.


Try to add this function to JTable

public function publish($pks = null, $state = 1, $userId = 0){
    $k = $this->_tbl_key;

    // Sanitize input.
    $userId = (int) $userId;
    $state = (int) $state;

    // If there are no primary keys set check to see if the instance key is set.
    if (empty($pks)){
            $pks = array($this->$k);
            return false;

    $pksImploded = implode(',', $pks);

    // Get the JDatabaseQuery object
    $query = $this->_db->getQuery(true);

    // Update the publishing state for rows with the given primary keys.
        ->set($this->_db->quoteName('state') . ' = ' . (int) $state)
        ->where($this->_db->quoteName($k) . 'IN (' . $pksImploded . ')');

    // Determine if there is checkin support for the table.
    $checkin = false;
    if (property_exists($this, 'checked_out_user_id') && property_exists($this, 'checked_out_time')){
        $checkin = true;
        $query->where(' (' . $this->_db->quoteName('checked_out_user_id') . ' = 0 OR ' . $this->_db->quoteName('checked_out_user_id') . ' = ' . (int) $userId . ')');

    }catch (RuntimeException $e){
        return false;

    // If checkin is supported and all rows were adjusted, check them in.
    if ($checkin && (count($pks) == $this->_db->getAffectedRows())){
        // Checkin the rows.
        foreach ($pks as $pk){
    // If the JTable instance value is in the list of primary keys that were set, set the instance.
    if (in_array($this->$k, $pks)){
        $this->state = $state;


    return true;

I looked into the default column for published and it is published and not state I just typically use this function to change that since most core components do that as well (seems a little odd).

| improve this answer | |
  • Thanks a lot Jordan. Sorry the question was ambiguous but I've edited it and hope it is more specific now. I used JModelList and JModelAdmin. I haven't gotten to creating new records or individual edits yet so I've not implemented JControllerForm yet. I didn't know about the state vs published columns so I'll try that after this commment. And finally, no, I'm not getting and errors. – Adewale Oluyinka Jun 6 '14 at 8:42
  • Here's the error I get now after changing published to state - WetvprogramschedulerTableDay: :publish failed - Unknown column 'published' in 'field list' SQL=UPDATE ddp04_wetv_programs_days SET published = 0 WHERE program_day_id = 0 – Adewale Oluyinka Jun 6 '14 at 9:18
  • Ok I made an update to the question that should fix the error. But also WHERE program_day_id = 0 it does not look like the proper ID is being set. <?php echo JHtml::_('grid.id', $i, $item->progam_day_id); ?> has a spelling error in your view. – Jordan Ramstad Jun 6 '14 at 16:51
  • Sorry I replied late - been attending to some more urgent jobs. I have checked and checked and checked but can't find any spelling error, progam_day_id is the name of the field I have been using from the database to the php files. It is working properly in the front end files, if the proper ID (in my case program_day_id) is the problem, I suppose it is only in the backend list view that it is not working as it should. Thanks for you help so far @Jordan Ramstad – Adewale Oluyinka Jun 9 '14 at 8:06
  • it seems to be missing an r, unless that is deliberate. The place i see this in is where the checkbox is generated, which is used for the publish button to send the id. If none is there it would show 0. This looks like your problem but again its just speculation. – Jordan Ramstad Jun 9 '14 at 18:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.