基本上我有一个具有多个功能的帮助文件。我在配置文件中自动加载帮助程序,因此理论上不需要重新加载它。
但是,当我尝试在我正在处理的新库中使用我创建的函数(来自这个帮助程序)时,它将通过这个错误:
"Parse error: syntax error, unexpected '(', expecting ',' or ';' in /home/techwork/public_html/giverhub/application/libraries/Udetails.php on line 7"
每当我在其他任何地方(模块、控制器、视图)使用该功能时,它都可以正常工作。
然后我阅读并认为也许我应该按照以下说明尝试加载帮助程序:http: //codeigniter.com/user_guide/general/creating_libraries.html
并尝试引用和加载,但这也是通过错误:
"Parse error: syntax error, unexpected T_VARIABLE, expecting T_FUNCTION in /home/techwork/public_html/giverhub/application/libraries/Udetails.php on line 5"
这是图书馆:
class Udetails{
$CI =& get_instance();// referencing as described in their website
$CI->load->helper('mylogin_helper');// loading the helper
public $member_session = is_member(); // using the function
public $username = $member_session['username'];
public $current_uID = $member_session['id'];
public $member_status = $member_session['status'];
}
这是助手中的函数:
if ( ! function_exists('is_member'))
{
function is_member(){
$CI =& get_instance();
$is_logged_in = $CI->session->userdata('is_logged_in');
$username = $CI->session->userdata('username');
$capabilities = $CI->session->userdata('capabilities');
$user_id = $CI->session->userdata('id');
switch ($capabilities){
case 'registered':
$level = 1;
break;
case 'confirmed':
$level = 2;
break;
case 'charity_admin':
$level = 3;
break;
case 'admin':
$level = 4;
break;
case 'super_admin':
$level = 5;
break;
default:
$level = 0;
}
$userdetails = array();
if(isset($is_logged_in) && $is_logged_in == true){
if($level > 1){
$userdetails['username'] = $username;
$userdetails['status'] = TRUE;
$userdetails['id'] = $user_id;
return $userdetails;
}
}
}
}