CodeIgniter错误:致命错误:从上下文“CI_Loader”调用私有IOFactory :: __ construct()

时间:2014-08-22 06:25:48

标签: php codeigniter codeigniter-2

我试图通过codeigniter实现PHPExcel,我收到此错误     

 class Users extends CI_Controller {

/**
 * Index Page for this controller.
 *
 * Maps to the following URL
 *      http://example.com/index.php/welcome
 *  - or -  
 *      http://example.com/index.php/welcome/index
 *  - or -
 * Since this controller is set as the default controller in 
 * config/routes.php, it's displayed at http://example.com/
 *
 * So any other public methods not prefixed with an underscore will
 * map to /index.php/welcome/<method_name>
 * @see http://codeigniter.com/user_guide/general/urls.html
 */


public function _construct()
{
}



public function index()
{



    $this->load->library('phpexcel');
    $this->load->library('PHPExcel/iofactory');

    $objPHPExcel = new PHPExcel();
    $objPHPExcel->getProperties()->setTitle("title")
                     ->setDescription("description");


    // Assign cell values
    $objPHPExcel->setActiveSheetIndex(0);
    $objPHPExcel->getActiveSheet()->setCellValue('A1', 'cell value here');

    // Save it as an excel 2003 file
    $objWriter = IOFactory::createWriter($objPHPExcel, 'Excel5');

    $objWriter->save("nameoffile.xls");
}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

我收到此错误:

Fatal error: Call to private IOFactory::__construct() from context 'CI_Loader' in F:\xampp\htdocs\import\system\core\Loader.php on line 1099

1 个答案:

答案 0 :(得分:0)

类用户扩展CI_Controller {

function __construct()
{
    **parent::__construct();**
}
function index()
{
   $this->load->library('phpexcel');
   $this->load->library('PHPExcel/iofactory');

   $objPHPExcel = new PHPExcel();
   $objPHPExcel->getProperties()->setTitle("title")
                 ->setDescription("description");


   // Assign cell values
   $objPHPExcel->setActiveSheetIndex(0);
   $objPHPExcel->getActiveSheet()->setCellValue('A1', 'cell value here');

   // Save it as an excel 2003 file
   $objWriter = IOFactory::createWriter($objPHPExcel, 'Excel5');

   $objWriter->save("nameoffile.xls");
}

}

enter link description here