2

I'm programming an EE extension, and in the save_settings() method, if I redirect() (after unsuccessful data validation), the message stored in the set_flashdata() method doesn't show. If I comment the redirect and let the method put the user back in the main extensions page, then the flashdata shows up fine. It's only if I redirect that the data isn't shown.

This is my save settings method - as near as I can tell I'm not doing anything out of the ordinary - it's mostly boilerplate as near as I can tell. I'd be very appreciative of anybody that can shed light on this...

function save_settings(){

    // no unauthorized access
    if (empty($_POST)) {
        show_error($this->EE->lang->line('unauthorized_access'));
    }

    // get the routestring then convert it to an array
    $routestring = $this->EE->security->xss_clean($this->EE->input->post('routes'));
    $results = $this->routes_to_array($routestring);

    // if the conversion was ok:
    if ($results['status'] == 'success') {

        // update db
        $this->EE->db->where('class', __CLASS__);
        $this->EE->db->update('extensions', array('settings' => serialize(array('routes' => $results['results']))));

        // set flash data
        $this->EE->session->set_flashdata('message_success', "Routes updated.");

    // if something went wrong during conversion:  
    } else {

        // set flash data then redirect back to edit screen
        $this->EE->session->set_flashdata('message_failure', $results['message']);

        // IF I COMMENT THE FOLLOWING LINE, THE FLASH DATA SHOWS UP FINE
        $this->EE->functions->redirect(BASE.AMP.'C=addons_extensions'.AMP.'M=extension_settings'.AMP.'file=apsdsm_bossyboots');
    }              
}

OK, this is my view file - as far as I can tell this is as boiler plate as it gets. More boiler plate than a dish that's been held in scalding water for ten minutes.

<?php echo form_open('C=addons_extensions'.AMP.'M=save_extension_settings'.AMP.'file=apsdsm_bossyboots'); ?>

<table class="mainTable" border="0"cellspacing="0" cellpadding="0">
    <thead>
        <tr>
            <th>
                Routes
            </th>
        </tr>
    </thead>

    <tbody>

        <tr>
            <td>

                <?php echo form_textarea(array('name'=>'routes', 'value' => $routestring)) ?>

                <?php echo form_submit('submit', 'Update Routes', 'class="submit"') ?>
            </td>
        </tr>
    </tbody>
</table>

<?php echo form_close()?>
9
  • I think something else is going on here. That is almost exactly the same code I've used many times. Can you check Chrome/Firebug Network tab and make sure there aren't any stray redirects occurring? Commented Dec 29, 2012 at 20:09
  • OK: so I checked the Network data: the only redirect going on there is the one in my code, and it looks like the ext_flash cookie is being set correctly - I can see the correct error data being passed along in the headers, but it's not displaying...
    – apsdsm
    Commented Dec 30, 2012 at 2:21
  • Sorry, not ext_flash, I meant exp_flash.
    – apsdsm
    Commented Dec 30, 2012 at 2:36
  • What method you using to display the flash data? Commented Dec 30, 2012 at 19:10
  • I'm just letting the Expression Engine control panel take care of it - So, after the redirect I'm not including any special code in my 'save_settings' method or anything. I swear I've done that before and it's worked fine...
    – apsdsm
    Commented Dec 31, 2012 at 1:12

1 Answer 1

1

I'm not positive if this will work or not, but the CodeIgniter Session library has a method for keeping flashdata for more more request, I'd imagine this would help here.

Try adding this before the redirect: $this->EE->session->keep_flashdata('message_failure');

1
  • Unfortunately, though that method is declared in the CI lib, it doesn't seem to be in the EE version... Flags an undefined error message... Thanks for the suggestion though, I appreciate it!
    – apsdsm
    Commented Jan 2, 2013 at 16:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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