2017-08-30 346 views
0

他們已經更新了插件並按照這個替換了一些共享類:https://github.com/PHPOffice/PHPWord/releases 並且在升級phpword時,我遇到了這個錯誤。PHPOffice/Common使用PHPWord在codeigniter中找不到

A PHP Error was encountered 

Severity: Error 

Message: Class 'PhpOffice\Common\Text' not found 

Filename: Element/Text.php 

Line Number: 139 





<?php 
include_once(APPPATH."third_party/PHPWord/Autoloader.php"); 
if (!defined('BASEPATH')) 
    exit('No direct script access allowed'); 


use PhpOffice\PhpWord\Autoloader; 
use PhpOffice\PhpWord\Settings; 
Autoloader::register(); 
Settings::loadConfig(); 


class Test extends CI_Controller { 

    public function index() { 
       $phpWord = new \PhpOffice\PhpWord\PhpWord(); 
       $phpWord->getCompatibility()->setOoxmlVersion(14); 
       $phpWord->getCompatibility()->setOoxmlVersion(15); 

       $section = $phpWord->addSection(); 
       $html = '<p><strong style="font-weight: 600;"This is a heading</strong></p> 

       $filename = 'test.doc'; 

       \PhpOffice\PhpWord\Shared\Html::addHtml($section, $html); 
       $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007'); 
       $objWriter->save($filename); 
       header('Content-Description: File Transfer'); 
       header('Content-Type: application/octet-stream'); 
       header('Content-Disposition: attachment; filename='.$filename); 
       header('Content-Transfer-Encoding: binary'); 
       header('Expires: 0'); 
       header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); 
       header('Pragma: public'); 
       header('Content-Length: ' . filesize($filename)); 
       flush(); 
       readfile($filename); 
       unlink($filename); // deletes the temporary file 
       exit; 
     } 
} 

我有使用作曲家,我不知道如何,如果使用普通的共享庫:https://github.com/PHPOffice/Common

請幫助。

+0

分享您的控制器代碼。 – Tpojka

+0

@Tpojka編輯我的問題與控制器代碼 – woninana

+0

我不知道'共同'和文檔鏈接是什麼被打破。但我明白你的主要問題是'PHPWord'。對? – Tpojka

回答

0

你可以ssh服務器與終端使用作曲家和避免第三方目錄呢?我只是試圖用composer安裝PHPWord。成功。 Common目錄默認爲PHPWord包。但我有this issue。它可以解決this way或甚至更好this way。 我已經使用了基本代碼示例從PHPWord GitHub頁面。

最好在修復該行之前將PHPWord分叉到您自己的存儲庫中,並調用您的存儲庫以避免在更新軟件包的情況下將來會中斷。 我不知道他們爲什麼沒有解決這個問題。

關注these 4 steps能夠重現我自己用的作曲家。

然後,你的樣品類應該是這個樣子:

<?php 
defined('BASEPATH') OR exit('No direct script access allowed'); 

use PhpOffice\PhpWord\PhpWord; 

class Welcome extends CI_Controller 
{ 

    public function index() 
    { 
     try { 
      // code example from GitHub https://github.com/PHPOffice/PHPWord#getting-started 
      // without require 'bootstrap.php' line, following 4 steps you already auto-loaded classes 
    } catch (\Exception $e) { 
      echo $e->getMessage(); 
    } 
} 

,你應該得到的FCPATH位置helloWorld.docxhelloWorld.odthelloWorld.html文件。