2011-06-04 102 views
3

大家好我有一个站点控制器代码如下.....当我尝试执行此代码时,我得到一个奇怪的问题,如果我将__construct()函数全部取出对我来说工作得很好,但是,一旦我添加构造函数,我得到错误500内部服务器错误,任何人都可以帮助我?为什么添加一个CodeIgniter构造函数会产生错误500

<?php 

class site extends CI_Controller 
{ 

    function __construct() 
    { 
     parent::CI_Controller(); 
     $this->Logged_in(); 
    } 


    function after_logging() 
    { 
     $this->load->view('home'); 
    } 

    function Logged_in() 
    { 
     $is_logged_in = $this->session->userdata('is_logged_in'); 
     if(!isset($is_logged_in)|| $is_logged_in != TRUE) 
     { 
      die(); 
     } 
    } 

} 
+2

你尝试使用'父:: __构建的'父::是CI_Controller()'()'呢? – 2011-06-04 19:43:55

+0

感谢它的工作! – koool 2011-06-04 20:55:41

回答

6

这是CI 2.0吗?

在这种情况下,用这个构造函数:

public function __construct() 
{ 
    parent::__construct(); 
     // your code 
} 
+3

看起来他确实在版本2上,其中Controller重命名为CI_Controller。 @koool:用户指南参考在这里:http://codeigniter.com/user_guide/general/controllers.html#constructors – 2011-06-04 20:05:44

+1

谢谢大家它的工作 – koool 2011-06-04 20:55:51

+0

我做到了,但没有解决。 – devpro 2016-04-15 18:23:21

相关问题