问题描述
我已经在本地机器上安装了 Magento 2.3,安装顺利.我可以通过 localhost/magento 访问我的商店.我试图访问我的管理页面 localhost/magento/*****_pogi 但它给了我一个空白页面并重定向到 url http://localhost/magento/*****_pogi/*****/index/index/密钥/a062e79f617010c42b07d662103d5142cd9bbe86314fb54da3e4cb5542b11eee/.
I have installed Magento 2.3 on my local-machine, installation goes fine. I can access my store at localhost/magento. I tried to access my ***** page localhost/magento/*****_pogi but it gives me a blank page and redirected to the url http://localhost/magento/*****_pogi/*****/index/index/key/a062e79f617010c42b07d662103d5142cd9bbe86314fb54da3e4cb5542b11eee/.
到目前为止我尝试过的是启用开发模式,我在我的管理页面上看到了这个错误:
What I have tried so far is to enable development mode, and I see this error on my ***** page:
1 exception(s): Exception #0 (MagentoFrameworkExceptionValidatorException): Invalid template file: 'C:/xampp/htdocs/magento/vendor/magento/module- backend/view/*****html/templates/page/js/require_js.phtml' in module: 'Magento_Backend' block's name: 'require.js' Exception #0 (MagentoFrameworkExceptionValidatorException): Invalid template file: 'C:/xampp/htdocs/magento/vendor/magento/module-backend/view/*****html/templates/page/js/require_js.phtml' in module: 'Magento_Backend' block's name: 'require.js' #0 C:xampphtdocsmagentovendormagentoframeworkViewElementTemplate.php(301): MagentoFrameworkViewElementTemplate->fetchView('C:/xampp/htdocs...') #1 C:xampphtdocsmagentovendormagentoframeworkViewElementAbstractBlock.php(668): MagentoFrameworkViewElementTemplate->_toHtml()#2 C:xampphtdocsmagentovendormagentoframeworkViewResultPage.php(249): MagentoFrameworkViewElementAbstractBlock->toHtml() #3 C:xampphtdocsmagentovendormagentoframeworkViewResultLayout.php(171): MagentoFrameworkViewResultPage->render(Object(MagentoFrameworkAppResponseHttpInterceptor)) #4 C:xampphtdocsmagentogeneratedcodeMagentoBackendModelViewResultPageInterceptor.php(193): MagentoFrameworkViewResultLayout->renderResult(Object(MagentoFrameworkAppResponseHttpInterceptor)) #5 C:xampphtdocsmagentovendormagentoframeworkAppHttp.php(139): MagentoBackendModelViewResultPageInterceptor->renderResult(Object(MagentoFrameworkAppResponseHttpInterceptor)) #6 C:xampphtdocsmagentogeneratedcodeMagentoFrameworkAppHttpInterceptor.php(24): MagentoFrameworkAppHttp->launch() #7 C:xampphtdocsmagentovendormagentoframeworkAppBootstrap.php(258): MagentoFrameworkAppHttpInterceptor->launch() #8 C:xampphtdocsmagentoindex.php(39): MagentoFrameworkAppBootstrap->run(Object(MagentoFrameworkAppHttpInterceptor)) #9 {main}
推荐答案
这将是一个错误,解决了 此提交.作者将 $path 更改为
This would be a bug that addresses this commit. Author changed $path to
$this->fileDriver->getRealPath($path)
它只是在 $path 上调用 realpath() 但这可能会改变 $path 上以前受
which is simply calling realpath() on $path but that might change directory separators on the $path that previously were affected by
#/vendor/magento/framework/View/Element/Template/File/Validator.php:114 $filename = str_replace('\', '/', $filename);
在 Windows 操作系统上,这将恢复上述 str_replace 的更改,以便像
On a Windows OS this will revert changes of above str_replace so that a path like
D:/Magento2.3/vendor/magento
将被规范化为其特定于 Windows 的版本:
will be canonicalized to its Windows specific version:
D:Magento2.3vendormagento
并且这不会在 MagentoFrameworkViewElementTemplateFileValidator 类的 isPathInDirectories() 方法中导致成功的比较:
and this will not result in a successful comparison within isPathInDirectories() method of MagentoFrameworkViewElementTemplateFileValidator class:
foreach ($directories as $directory) { if (0 === strpos($realPath, $directory)) { return true; } }
解决方案
目前,我们可以在上面的 foreach 循环中进行肮脏的快速更改,以便我们可以运行我们的 magento 而不会出现更多问题:
Solution
Currently we can go for a dirty quick change in the above foreach loop so that we can run our magento with no further problems on this:
#/vendor/magento/framework/View/Element/Template/File/Validator.php:139 foreach ($directories as $directory) { // Add this line $realDirectory = $this->fileDriver->getRealPath($directory); // and replace `$directory` with `$realDirectory` if (0 === strpos($realPath, $realDirectory)) { return true; } }