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

  • Home
  • SEARCH
  • 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 8105355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:08:24+00:00 2026-06-06T00:08:24+00:00

I have a activate button in my CMS that allows the user to quickly

  • 0

I have a activate button in my CMS that allows the user to quickly toggle a active/inactive flag for news articles. When clicked the toggle makes a POST request to the url /news/toggle_active/$id, after which the news_model updates the boolean variable in the database for the specific articles id, and the controller redirects back to the index.

Controller

function toggle_active()
{
    $url = $this->uri->uri_string();
    $last_segment = count($this->uri->segment_array());
    $id = $this->uri->segment($last_segment);

    $row = $this->news_model->set_active($id);

    redirect('news/index', 'refresh');
}

Model

function set_active($id)
{
    $data = array(
           'display_flg' => 'NOT display_flg'
    );

    $this->db->where('id', $id);
    $this->db->update($this->tbl_news, $data);
}

The first time the activate button is clicked it works, but subsequent clicks do nothing. If I close the browser window and re-open the page, the button works again, but only for one click.

I haven’t specifically enabled any caching, so I’m not sure whats going on.

If I remove the redirect from the end of the toggle_active() method, and output the current value of the display_flg variable, and POST to /news/toggle_active/$id it appears to do nothing on the first request. However on each subsequent refresh the variable changes values. Why is it not doing anything the first time the link is hit?

I found some people with what seems to be a similar issue over at the codeigniter forums, although there was no solid solution.

  • 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-06T00:08:26+00:00Added an answer on June 6, 2026 at 12:08 am

    I don’t think this was a caching problem in the end. I made two major changes to fix the problem.

    Firstly, I not check to see whether or not the database request was successful before redirecting.

    I also re-wrote my the models set_active() method. Passing the SET clause as an array to the update functions second parameter wasn’t working. I needed to use the set functions third parameter to stop the query from escaping the NOT part of the query.

    I adjusted my functionality as follows:

    Controller

    function show_toggle($id)
    {
        if($this->news_model->set_active($id)) 
        {
            redirect('news/index', 'refresh');
        }
    }
    

    Model

    function set_active($id)
    {
        $this->db->where('id', $id);
        $this->db->set('display_flg', 'NOT display_flg', FALSE);
        $query = $this->db->update($this->tbl_news);    
    
        return $query;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a button on a spreadsheet that, when pressed, should allow the user
I have two buttons that are meant to activate my JavaScript functions when clicked,
I have a div that I have bound the jQuery hover event to activate
I have a jquery overlay window in my html alongwith a button to activate
I have an UpdateProgress control to activate on a postback of a button control.
I have a custom toolbar that fires events on html button click, there is
I have an app that plays some background music, when a certain button is
Have any one tried to activate fancybox thumbnail gallery using a button or an
Say that I have three button elements in one parent div. Assuming that these
I have a movieClip with a button that I created inside of my display

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.