【问题标题】:Class 'PhpOffice\PhpWord\Settings' not found in app/code/core/Mage/Core/Model/Config.php on line 1348在第 1348 行的 app/code/core/Mage/Core/Model/Config.php 中找不到类“PhpOffice\PhpWord\Settings”
【发布时间】:2016-02-19 04:19:01
【问题描述】:

升级到 PHP 7 后,我的网站 magento 使用 PhpWord 库打印订单无法正常工作。

我有这个错误:

不能使用 PhpOffice\PhpWord\Shared\String 作为字符串,因为 'String' 是 /home/.../vendor/phpoffice/phpword/src/PhpWord/Style/Paragraph.php 中的特殊类名

然后我使用最新的 PhpOffice/PhpWord 和 PhpOffice/Common 但它显示下一个错误:

致命错误:在第 1348 行的 /app/code/core/Mage/Core/Model/Config.php 中找不到类“PhpOffice\PhpWord\Settings”

你能帮我解决这个错误吗?

【问题讨论】:

    标签: php magento


    【解决方案1】:

    解决方案:

    将文件phpoffice/phpword/src/PhpWord/Shared/String.php 重命名为phpoffice/phpword/src/PhpWord/Shared/StringHelper.php。使用对多个文件具有搜索和替换功能的文本编辑器或像 findsed 这样的命令外壳工具来搜索行 use PhpOffice\PhpWord\Shared\String; 并用一行替换每个行 use PhpOffice\PhpWord\Shared\StringHelper; 。这意味着整个单词 String 在所有 PHP 文件的所有位置都必须替换为 StringHelper。同时搜索 String:: 并将其替换为 'StringHelper::` 。

    说明:

    String 类似乎被 PHP 保留,甚至不允许命名空间。解决方法:使用类名StringHelper代替它。

    Linux Shell:

    find . -name '*.php'  -exec grep -nw String {} \; -ls
    

    这将列出您必须进行替换的所有文件和行号。

    【讨论】:

      【解决方案2】:

      解决方案 1: 我在整个 phpword 库中将类 String 重命名为 Stringg,这对我也适用于 php7 和旧版本的 php..

      解决方案 2: 或者可以通过为字符串类提供别名来使用,例如

      use PhpOffice\PhpWord\Shared\String as POString;
      

      现在使用下面提到的 POString。

      public function setText($text)
      {
      $this->text = POString::toUTF8($text);
      return $this;
      }
      

      这也可以正常工作

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2023-03-12
        • 2011-11-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-03-13
        • 1970-01-01
        相关资源
        最近更新 更多