Explanation:
1) Regardless of the technology used in programming, do not mix PHP code with Javascript;
2) The redirect which is a helper of Codeigniter, has the function of redirecting to the specified address, and internally would be a header("Location: /administracao/categorias");
then, it won’t even run the last line that is a Javascript code (follow recommendation item 1). ). See 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 the redirect
, use a $this->session
with the method flashdata
, which is intended 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:
It worked perfect, thank you
– Andrew Maxwell