php - how to check session flashdata in helper in CI
686
To check and display a session, I usually do this:
$alert = $this->session->flashdata('alert');
if($alert)
{
?>
<div role="alert">
<button type="button" data-dismiss="alert"><span aria-hidden="true">×</span><span >Close</span></button>
<?php echo $var; ?>
</div> <?php
}
But the result is sloppy. I want to make a "ECHO" of a function and that function contains everything you need to check and display the session. So I try to do this in form helper:
function errors_session()
{
$ci =& get_instance();
if( $this->ci->session->flashdata() == TRUE )
{
return '<div class="error">'. $this->ci->session->flashdata() .'</div>';
}
return '';
}
but this not work
Answer
Solution:
in Controller file:
in View file:
or
Answer
Solution:
Ah should have spotted that. Its as the error says- you can't use $this you need to change to use the $ci object you have created like this