class Project extends ci_Controller
{
public var $email=$this->session->userdata('email');
if(!isset($_SESSION['email']))
{
echo "you are not logged in ";
exit();
}
}
错误消息:
解析错误:语法错误,意外' $ this' (T_VARIABLE)
答案 0 :(得分:1)
尝试使用索引方法的代码:
class Project extends CI_Controller
{
function __construct() {
parent::__construct();
}
function index(){
$email = $this->session->userdata('email');
if(!isset($_SESSION['email']))
{
echo "you are not logged in ";
exit();
}
}
}
答案 1 :(得分:0)
因为您正在访问$this
外部函数/构造函数。(有关详细信息,请参阅@ Rizier123 注释)另请使用CI_Controller
而不是ci_Controller
尝试创建函数像
class Project extends CI_Controller
{
public function my_func() {
$email=$this->session->userdata('email');
if(!isset($_SESSION['email']))
{
echo "you are not logged in ";
exit();
}
}
}