我有PHPExcel,我想將它添加到CodeIgniter中。CodeIgniter + PHPExcel:將這個庫調用到CodeIgniter的最佳方式是什麼?
哪裏最好從所有CodeIgniter文件夾複製文件,以及如何在我的控制器/模型中將其稱爲常規用法?
編輯:
這是一個整個文件夾,我需要移動,並調用主文件:PHPExcel\IOFactory.php
我有PHPExcel,我想將它添加到CodeIgniter中。CodeIgniter + PHPExcel:將這個庫調用到CodeIgniter的最佳方式是什麼?
哪裏最好從所有CodeIgniter文件夾複製文件,以及如何在我的控制器/模型中將其稱爲常規用法?
編輯:
這是一個整個文件夾,我需要移動,並調用主文件:PHPExcel\IOFactory.php
您可以在笨添加PHPExcel
到庫,如:
application > libraries > PHPExcel.php
讓我們說PHPExcel.php
lib rary文件:
<?php
if (!defined('BASEPATH')):
exit('No direct script access allowed');
endif;
class PHPExcel
{
public function __construct()
{
//
}
public function some_function()
{
return 'some_function';
}
}
要在Controller中調用PHPExcel
庫。讓說,我把它命名爲 My_controller.php
:
<?php
if (!defined('BASEPATH')):
exit('No direct script access allowed');
endif;
class My_controller extends CI_Controller
{
public function __construct()
{
parent::__construct();
//Call PHPExcel class
$this->load->library('PHPExcel');
}
public function index()
{
echo $this->PHPExcel->some_function();
}
}
我跟着這個教程:https://arjunphp.com/how-to-use-phpexcel-with-codeigniter/
得到了我的答案!
我看到你做了什麼,我有一些問題,然後我嘗試這樣做: 第一:我應該將PHPExcel文件夾移動到哪個目錄?第二:如何在編輯我的問題後應用此功能,因爲您現在知道這是一個包含文件的整個文件夾,而不僅僅是一個文件夾。 –
那麼你可以創建一個文件夾並將其命名爲PHPExcel並將所有文件移入它。你只需要調用主文件作爲你提到 - IOFactory.php欲瞭解更多信息...只需去http://ellislab.com/codeigniter/user-guide/general/creating_libraries.html – Nere