[eluser]jloosli[/eluser]
I've been playing around with this and came up with a workaround that works fairly well for me.
What I've done is simulate a redirect through an automatic form submission:
First, create a view called "redirect_with_message.php" (codeigniter removes the script tags, so put them in when you create your file):
Code:
//script tag goes here
function auto() {
document.myform.submit();
}
//closing script tag goes here
<body>
<?php echo form_open($to,array('name'=>"myform")); ?>
<input type="hidden" value="<?php echo $message; ?>" name="message">
</form>
</body>
Then create a helper entitled "redirect_helper.php" and place it in your helpers directory. I also added "redirect" to $autoload['helper']:
Code:
<?php
/**
* Simulates a redirect, but sends message as well.
* @param string $loc Codeigniter URI
* @param string $message Message to be sent
* @param string $field Defaults to 'message', but you could change it to something else
* @return void
*/
function redirect_msg($loc,$message="", $field="message") {
$CI=&get;_instance();
$data=array(
"to"=>$loc,
$field=>$message
);
$CI->load->view('redirect_with_message',$data);
}
/*
* Returns either the flashdata field or the posted field.
*/
function showmsg($field='message') {
$CI=&get;_instance();
return $CI->session->flashdata($field).$CI->input->post($field);
}
Now, if I want to send a message along with the redirect, I use
Code:
<?php
redirect_msg('path/to/controller/method',"This message was sent");
and in the view, I put
Code:
<?php
echo $showmsg;
and my message comes across whether or not I use the regular flashdata, or redirect_msg().