gpt4 book ai didi

php - 在 Windows 10 上安装 Magento 2.3 后管理页面空白

转载 作者:可可西里 更新时间:2023-11-01 13:42:25 26 4
gpt4 key购买 nike

我正在使用 xampp 在 Windows 10 上本地安装 Magento 2.3。我从 Github 下载存档,解压缩到 c:\xampp\htdocs\magento2,然后在我的浏览器中从 localhost/magento2/setup 运行安装程序。

安装程序已完成,没有任何错误,但是当我转到管理页面时,我看到一个背景为灰色的空白页面。当我转到 localhost/magento2 时,我得到了这个

I get this

当我查看 magento2/var/log/system.log 时,会出现一些类似以下内容的错误(对于不同文件名的列表,每个错误都会重复多次)

main.ERROR:“C:/xampp/htdocs/magento2/lib/web/requirejs/require.js”的符号链接(symbolic link)无法创建并放置到“C:/xampp/htdocs/magento2”/pub/static/adminhtml/Magento/backend/en_US/requirejs/require.js”。警告!符号链接(symbolic link)():无法创建符号链接(symbolic link),错误代码(1314)[] []
) [] []

main.CRITICAL:无效的模板文件:模块中的“C:/xampp/htdocs/magento2/app/code/Magento/Backend/view/adminhtml/templates/page/js/require_js.phtml”:“Magento_Backend' block 的名称:'require.js' [] []

编辑:

我通过更改 magento\lib\internal\Magento\Framework\View\Element\Template\File\Validator.php 中的代码让管理页面正常工作

原代码是

public function isValid($filename)
{
$filename = str_replace('\\', '/', $filename);
if (!isset($this->_templatesValidationResults[$filename])) {
$this->_templatesValidationResults[$filename] =
($this->isPathInDirectories($filename, $this->_compiledDir)
|| $this->isPathInDirectories($filename, $this->moduleDirs)
|| $this->isPathInDirectories($filename, $this->_themesDir)
|| $this->_isAllowSymlinks)
&& $this->getRootDirectory()->isFile($this->getRootDirectory()->getRelativePath($filename));
}
return $this->_templatesValidationResults[$filename];
}

我改成了

public function isValid($filename)
{
return true;
}

因为我是 Magento 的新手,所以我不明白这个方法应该做什么(我假设它正在验证模板文件,但我不知道如何或在哪里)。此外,当我在原始代码中添加一条日志语句以显示 $this->_templatesValidationResults[$filename] 的内容时(就在 return 语句之前),它打印了几个空数组元素。例如,它打印了

[] []  
[] []
[] []
[] []

Magento 似乎认为模板文件无效,但没有给出它们无效的任何原因。我这样说对吗?我该如何阻止 Magento 错误地将模板文件检测为无效,或者获取正确的验证错误消息?

可能的解决方案和进一步的问题

我将问题追溯到文件magento\lib\internal\Magento\Framework\View\Element\Template\File\Validator.php

在函数中

protected function isPathInDirectories($path, $directories)
{
if (!is_array($directories)) {
$directories = (array)$directories;
}
$realPath = $this->fileDriver->getRealPath($path);
foreach ($directories as $directory) {
if (0 === strpos($realPath, $directory)) {
return true;
}
}
return false;
}

问题是 $path 中有正斜杠,但是 $realPath 有反斜杠,所以 strpos 永远不会返回匹配项,并且该函数始终返回 false。我将函数更新为

protected function isPathInDirectories($path, $directories)
{
if (!is_array($directories)) {
$directories = (array)$directories;
}
$realPath = $this->fileDriver->getRealPath($path);
foreach ($directories as $directory) {
if (0 === strpos($realPath, $directory) || 0 === strpos($path, $directory)) {
return true;
}
}
return false;
}

现在可以了。我认为这是一个仅限 Windows 的问题?这是 Magento 中没有考虑 Windows 文件命名的错误,还是我在设置中做错了什么?

最佳答案

我对 Windows 10 上的 magento 2.3 有同样的问题,后台页面显示棕色背景的空白页面。

在网上搜索问题后,终于找到了解决方案

  1. 打开magento安装目录下的文件/vendor/magento/framework/View/Element/Template/File/Validator.php,找到

    $realPath = $this->fileDriver->getRealPath($path);

替换为:

$realPath = str_replace('\\', '/', $this->fileDriver->getRealPath($path));

终于显示登录页面,但是登录页面和登录后都没有图标

  1. 打开magento安装目录下的app/etc/di.xml文件,找到

    Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink

并替换为

Magento\Framework\App\View\Asset\MaterializationStrategy\Copy
  1. 然后到var/cache,删除所有文件夹/文件
  2. 刷新页面,完成。

关于php - 在 Windows 10 上安装 Magento 2.3 后管理页面空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53565012/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com