我正在尝试使用 PHPWord,但使用起来有困难。
这是我在 application/libraries/words.php 中的代码
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require_once APPPATH."/third_party/PhpWord/Autoloader.php";
\PhpOffice\PhpWord\Autoloader::register(); \\NOT SURE IF THIS IS CORRECT
class Word extends PhpWord {
public function __construct() {
parent::__construct();
}
}
基于 PHPWord github,我必须像这样使用它:
Alternatively, you can download the latest release from the releases page. In this case, you will have to register the autoloader.
require_once 'path/to/PhpWord/src/PhpWord/Autoloader.php';
\PhpOffice\PhpWord\Autoloader::register(); // WHERE SHOULD I PUT THIS?
当我尝试从我的控制器加载库时:
$this->load->library('word');
它给了我一个错误,上面写着:
Fatal error: Class 'PhpWord' not found in C:\xampp\htdocs\path\to\application\libraries\Word.php on line 7
我试图扩展 Autoloader 类,但 PHP 仍然抱怨它找不到 Autoloader.php。
当我做
file_exist(APPPATH."/third_party/PhpWord/Autoloader.php") // Similarly with PhpWord.php
它返回 1。
有谁知道如何解决这一问题?