duandian4501 2019-04-09 14:17
浏览 3168

找不到类'PhpOffice \ PhpWord \ TemplateProcessor'

I have PHPWORD in /libraries/PhpOffice/PhpWord/ directory. I'm trying to use it in completly other part of app (Joomla website) like this:

require_once JPATH_LIBRARIES.'/vendor/autoload.php'; //composer
require_once JPATH_LIBRARIES.'/PhpOffice/PhpWord/PhpWord.php';
$Wzor = new \PhpOffice\PhpWord\TemplateProcessor(JPATH_ROOT.'/images/powiadomienia/SzablonPowiadomienia.docx');

But I get error:

Class 'PhpOffice\PhpWord\TemplateProcessor' not found

I tried many variants and paths, I tried to read online help but always with the same result. Can I ask for for some help and guidance? How can I include such class to my script?

  • 写回答

2条回答 默认 最新

  • douxun2023 2019-04-09 18:46
    关注

    Use the /vendor folder, not "libraries" (see why below).

    In your project root folder:

    composer require phpoffice/phpword
    

    Then:

    require_once JPATH_ROOT.'/vendor/autoload.php';
    $Wzor = new \PhpOffice\PhpWord\TemplateProcessor(JPATH_ROOT.'/images/powiadomienia/SzablonPowiadomienia.docx');
    

    WARNING:

    NEVER run a "composer require" inside the "/libraries" folder as it WILL DELETE the Joomla core on more recent versions. This happens because people were using this folder and to emphatize that it shouldn't be used, the Joomla core team removed the composer.json file from it. Because of this, the Joomla core is wiped out when trying to add libraries on this folder.


    Why not use "/libraries"?

    From https://docs.joomla.org/J3.x:Using_Composer_with_Joomla:

    Can you install any extra libraries via Composer?

    Not at the moment in Joomla! 3.4. In the longer term it is the CMS's aim that you can download extra packages. To emphasize this, we will not yet be releasing the composer.json file within the main Joomla! download.

    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)