Explanation:
1)
2) The redirect > which is a CodeIgniter helper , is to redirect to the specified address, and internally would be header("Location: /administracao/categorias");
so it will neither run the last line which is a Javascript code (follow recommendation item 1). See the code below:
function redirect($uri = '', $method = 'location', $http_response_code = 302)
{
if ( ! preg_match('#^https?://#i', $uri))
{
$uri = site_url($uri);
}
switch($method)
{
case 'refresh':
header("Refresh:0;url=".$uri);
break;
default:
header("Location: ".$uri, TRUE, $http_response_code);
break;
}
exit;
}
3) Solution:
In your method before redirect
, use a $this->session
with the method flashdata
, which is meant to be active only until the next server request and immediately after it is automatically deleted.
Method:
$data['categoria'] = $this->input->post('categoria');
$data['slug_categoria'] = $this->input->post('slug_categoria');
$this->db->insert('categorias', $data);
$this->session->set_flashdata('acaoform', 'Inseridos !!!.');
redirect('administracao/categorias');
View
<?php
$acaoflash = $this->session->flashdata('acaoform');
if (isset($acaoflash) && $acaoflash!=''){
echo "<script>alert('".$acaoflash."')</script>";
}
?>
References: