将函数中的会话变量传递给codeigniter中的帮助器 [英] passing a session variable in a function to a helper in codeigniter
本文介绍了将函数中的会话变量传递给codeigniter中的帮助器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这就是我想要做的。这是控制器中的函数
Here's what I'm trying to do. This is the function in the controller
public function get_started()
{
if(test_login($this->session->all_userdata())) {
$this->load->view('template');
} else {
$this->load->view('error');
}
}
这是助手
function test_login($sessdata)
{
if($sessdata->userdata('is_logged_in')) {
return true;
} else {
return false;
}
}
我已输入 is_logged_in
作为布尔会话变量。
但是,这不起作用。
I have entered is_logged_in
as a boolean session variable.
However, this doesn't work.
我找不到错误。
推荐答案
您可以从帮助程序本身访问会话,而不必将会话数据作为参数传递给您的帮助程序,例如:
instead of passing session data as parameter to your helper, you could access the session from helper itself, like:
function test_login() {
$CI = & get_instance(); //get instance, access the CI superobject
$isLoggedIn = $CI->session->userdata('is_logged_in');
if( $isLoggedIn ) {
return TRUE;
}
return FALSE;
}
和控制器:
public function get_started(){
if( test_login() ) {
$this->load->view('template');
}
else {
$this->load->view('error');
}
}
这篇关于将函数中的会话变量传递给codeigniter中的帮助器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文