使用 codeigniter 和 flexiauth 显示闪存数据

Display flashdata with codeigniter and flexiauth

当用户试图访问他没有权限的页面时,我试图显示一条(闪光)消息。

我创建了一个加载视图的控制器:

function index()
{                                                                                       

    // Check user is allowed to open this       

    if ($this->flexi_auth->is_privileged('Wizard'))     
        {       

        $this->load->view('portal/wizard/wizard_view');     

        }       
        else        

        {               
            // Set a custom error message.
            $this->flexi_auth->set_error_message('Sorry, you are not allowed to view this!', TRUE);
            $this->session->set_flashdata('message', $this->flexi_auth->get_messages());
            redirect('auth_lite/portal');


        }
}

如果用户没有向导权限,它将重定向到主页 (auth_lite/portal) 并应显示一条错误消息(不允许...)。

在我的 auth_lite 控制器中,我为门户功能设置了这个:

function portal()
{
        if ($this->flexi_auth->is_logged_in())
    {


    // Get any status message that may have been set.
    $this->data['message'] = $this->session->flashdata('message');

    $this->load->view('portal_view');


    }
    else
    {
        redirect('auth/login');
    }

}

在我的视图文件中,消息显示如下:

            <?php if (! empty($message)) { ?>
            <div id="message">
                <?php echo $message; ?>
            </div>
        <?php } ?>

但是,闪现信息没有按预期显示。我已经阅读了文档,但我不确定我做错了什么。

感谢您的帮助!

从 auth_lite 控制器中删除以下行

$this->data['message'] = $this->session->flashdata('message');

并更改视图中的错误消息

 <?php if($this->session->flashdata('message')) { ?>
     <div id="message">
        <?php echo $this->session->flashdata('message'); ?>
     </div>
 <?php } ?>