2017-08-30 8 views
0

https://github.com/PHPOffice/PHPWord/releases のようにプラグインを更新して共有クラスを置き換えましたが、phpwordのアップグレード時にこのエラーが発生しました。PHPOffice/common codeigniterでPHPWordを使用していません

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

で私の質問を編集しました。どのようなものが 'Common'であるのか分からず、docsへのリンクが壊れています。しかし、あなたの主な問題は 'PHPWord'だと私は理解しました。右? – Tpojka

答えて

0

ターミナルでサーバをsshして、コンポーザを使用し、サードパーティのディレクトリを避けることはできますか?私はちょうど作曲家とPHPWordをインストールしようとしました。成功しました。一般的なディレクトリはデフォルトで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ファイルを取得する必要があります。

関連する問題