类 'PhpOfficePhpWordSettings' 在 app/code/core/Mag


Class 'PhpOfficePhpWordSettings' not found in app/code/core/Mage/Core/Model/Config.php on line 1348

升级到 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'

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

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

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

use PhpOffice'PhpWord'Shared'String as POString;

现在使用如下所述的POString。

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

这也可以正常工作

解决方案:

将文件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;替换每个行。这意味着必须在所有 PHP 文件的所有位置将整个单词String替换为StringHelper。还要搜索String::并将其替换为"StringHelper::"。

解释:

String似乎是由 PHP 保留的,甚至不允许使用命名空间。解决方案:使用类名StringHelper而不是它。

Linux Shell:

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

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