Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CodeIgniter: View doesn't load if I use die() function

I have the following code. Checks if the user is logged in or not. When the variable $is_logged_in is not set or is False, I load a message view. Unfortunately, at the same time the system loads the restricted content view. So I used die() function, and now only shows a blank page.

What can I do to only load the message view when the user is not logged in? Thanks.

if(!isset($is_logged_in) OR $is_logged_in == FALSE)
{
     $data['main_content'] = 'not_logged_in';

     $data['data'] = '';

     $this->load->view('includes/template',$data);

     die();
}
like image 586
T.C Avatar asked Nov 28 '22 11:11

T.C


1 Answers

Actually, I've found an answer to mantain the URL and not redirect:

$data['main_content'] = 'unauthorized_access';
$this->load->view('includes/template', $data);

// Force the CI engine to render the content generated until now    
$this->CI =& get_instance(); 
$this->CI->output->_display();

die();
like image 162
Ricardo Souza Avatar answered Dec 10 '22 22:12

Ricardo Souza