Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9182783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:38:34+00:00 2026-06-17T18:38:34+00:00

The Joomla com_content has small toggle button for the article’s status publish to publish

  • 0

The Joomla com_content has small toggle button for the article’s status “publish” to publish or unpublish the articles. So, I want to have same type of toggle button in my component also to approve or disapprove users.

Now, I want some advice from experts on how to go about. I have gone through com_content but I don’t really understand that how should i begin. I can’t understand com_content approach and code because I am not coding in line with Joomla 2.5.

How should I start with this ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T18:38:36+00:00Added an answer on June 17, 2026 at 6:38 pm

    i made it work on my own. let me share the experience for those who will need it in future. my table field or database field is approved and its value is 0 initially (which means the record is unapproved by the admin)

    in my layout/default page i have the code as below for the toggle button:

        <?php
        $k = 0;
        for ($i=0, $n=count( $this->items ); $i < $n; $i++)
        {
           $row = &$this->items[$i];
        ..................
        ..................
        ?>
        ..................
    
        <td align="center">
           <?php echo JHtml::_('job.approve', $row->approved, $i); ?>
        </td>
    

    Note that i’ve $row->approved which is my field from db. then i’ve job.approve for which i have created a job.php file and placed in helpers directory. the code for job.php is:

    <?php
    // no direct access
    defined('_JEXEC') or die;
    
    /**
     * @package     Joomla.Administrator
     * @subpackage  com_content
     */
    abstract class JHtmlJob
    {
        /**
         * @param   int $value  The state value
         * @param   int $i
         */
        static function approve($value = 0, $i)
        {
            // Array of image, task, title, action
            $states = array(
                0   => array('disabled.png',    'approve',  'Unapproved',   'Toggle to approve'),
                1   => array('tick.png',        'unapprove',    'Approved',     'Toggle to unapprove'),
            );
            $state  = JArrayHelper::getValue($states, (int) $value, $states[1]);
            $html   = JHtml::_('image', 'admin/'.$state[0], JText::_($state[2]), NULL, true);
            //if ($canChange) {
                $html   = '<a href="#" onclick="return listItemTask(\'cb'.$i.'\',\''.$state[1].'\')" title="'.JText::_($state[3]).'">'
                        . $html.'</a>';
            //}
    
            return $html;
        }
    }
    

    Then i’ve registered two tasks in controller as approve and unapprove along with approve function:

    public function __construct($config = array())
        {
            parent::__construct($config);
    
            $this->registerTask('unapprove', 'approve');
        }
    
        /**
         * Method to toggle the featured setting of a list of articles.
         *
         * @return  void
         * @since   1.6
         */
        function approve()
        {
            // Initialise variables.
            $user   = JFactory::getUser();
            $ids    = JRequest::getVar('cid', array(), '', 'array');
            $values = array('approve' => 1, 'unapprove' => 0);
            $task   = $this->getTask();
            $value  = JArrayHelper::getValue($values, $task, 0, 'int');
    
            if (empty($ids)) {
                JError::raiseWarning(500, JText::_('JERROR_NO_ITEMS_SELECTED'));
            }
            else {
                // Get the model.
                $model = $this->getModel('jobs');
    
                // Publish the items.
                if (!$model->approve($ids, $value)) {
                    JError::raiseWarning(500, $model->getError());
                }
            }
    
            $redirectTo = JRoute::_('index.php?option='.JRequest::getVar('option'));
            $this->setRedirect($redirectTo);
        }
    

    Thereafter, i’ve added the following function in model to update the value to 0 or 1.

    function approve($cid, $publish) {
    
             if (count( $cid ))
             {
                 JArrayHelper::toInteger($cid);
                 $cids = implode( ',', $cid );
                 $query = 'UPDATE #__tbljobs'
                       . ' SET approved = '.(int) $publish
                       . ' WHERE id IN ( '.$cids.' )';
                      $this->_db->setQuery( $query );
                    if (!$this->_db->query()) {
                        $this->setError($this->_db->getErrorMsg());
                        return false;
                     }
               }
               return true;
     }
    

    Please don’t forget to include the job.php file in your view/view.html.php file as below:

    <?php
    defined('_JEXEC') or die('Restricted Access');
    jimport('joomla.application.component.view');
    
    require_once JPATH_COMPONENT .'/helpers/job.php';
    
    Class JobsViewListJobs extends JView
    {
    

    And remember i am not using JForm nor my code is in joomla 1.7 style. But i am following the MVC architecture. So, i am not sure if my method will work for people who are coding in joomla 1.7 and above style.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a url on my joomla site http://www.mysite.com/index.php?option=com_content&view=frontpage&Itemid=3220 My Customer wants it to
In Joomla 1.5 I would like to have a startpage (that has its own
I want to modify a native joomla module that display articles of a category.
I have a bunch of categories and items in Joomla and I want one
Has anyone built a version of the com_content Joomla 1.5 component? I've got a
I'm just getting into Joomla. I've successfully overridden article pages by creating an html/com_content/article
We have a Joomla 1.5 site here : http://printversal.com It got hacked last night.
I have a Joomla Website located at http://www.MikeSilvis.com , and upon going to the
With Joomla, I'm using LoadModule plugin to inlude a auhentication module into an article,
I am not really familiar with Joomla but I have been tasked with writing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.