CodeIgniter:如果我使用die()函数,视图不加载 [英] CodeIgniter: View doesn't load if I use die() function

查看:143
本文介绍了CodeIgniter:如果我使用die()函数,视图不加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码。检查用户是否已登录。
当变量$ is_logged_in未设置或为False时,我加载一个消息视图。
不幸的是,系统加载受限内容视图的同时。
所以我使用die()函数,现在只显示一个空白页。

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();
}


推荐答案

我使用重定向到登录页面和flashdata变量

Anyway. I used a redirect to the login page, and a flashdata variable

if(!isset($is_logged_in) OR $is_logged_in == FALSE)
   {
       $this->session->set_flashdata('error_msg','You must be logged in to access restricted area');
       redirect('login/');
   }

感谢

这篇关于CodeIgniter:如果我使用die()函数,视图不加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆