잘못된 템플릿 파일 magento2.3.0


13

최근에 로컬 에이전트 컴퓨터에 magento 최신 버전, 즉 Magento 2.3.0을 설치했습니다. php 7.2.4

명령 행 인터페이스를 사용하여 설치했습니다.

하지만 내가 피곤하면 나에게 오류를 보여줍니다.

Exception #0 (Magento\Framework\Exception\ValidatorException): Invalid template file: 'D:/wamp64/www/mage23/vendor/magento/module-theme/view/frontend/templates/page/js/require_js.phtml' in module: '' block's name: 'require.js'

당신을 위해 일하고 있습니까?
Rohan Hapani

여전히 모든 확장이 작동하지는 않습니다.
MageLerner

답변:


37

예, 이것은 Windows의 문제입니다. Windows는 "\"를 구분 기호로 사용하고 배열 "디렉토리"에는 "/"가 구분 기호로 포함 된 항목이 포함되므로 검사가 항상 실패합니다. 따라서 핵심 파일에서 구분 기호를 바꾸어이 문제를 해결해야합니다.

Magento\Framework\View\Element\Template\File\Validator

기능 isPathInDirectories은 코드 아래에 대체 isPathInDirectories 기능

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

이것은 매우 일반적인 문제입니다. 많은 사람들이 Magento가 공식적으로 Windows 서버를 지원하지 않는다는 사실을 알고 있지 않습니다! Windows 컴퓨터에서 작동하도록하기 위해 이와 같은 일부 해킹 및 비공식 수정을 수행해야합니다. 아래 링크 "Magento 2.3.x 기술 스택 요구 사항"을 방문하면 유일하게 지원되는 OS는 다음과 같습니다. "리눅스 x86-64". devdocs.magento.com/guides/v2.3/install-gde/…
Yacoub Oweis

Windows 시스템의 경우 실제 코드는 무엇입니까? 나는 먼저 '\'라인을 시도하고 있지만이 단일 백 슬래시는 허용되지 않습니다 ...
Flutterer

좋아, 그래서 그들은 공식적으로 Windows를 지원하지 않지만 DIRECTORY_SEPARATOR다른 세계처럼 사용할 수는 없으며 Windows에서 작동하는 유일한 문제처럼 보이지 않는이 특정 문제를 가질 수 없었습니까?
ACJ

10

나를 위해 해결책은 \ vendor \ 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);
>     $realPath = str_replace('\\', '/', $realPath); // extra code added
>     foreach ($directories as $directory) {
>         if (0 === strpos($realPath, $directory)) {
>             return true;
>         }
>     }
>     return false; }

추신 : 이것은 Windows 관련 문제입니다.



3

Magento 2.3.0의 핵심 문제이지만 Magento 2.2.7에서도 그 문제에 직면했습니다. realpath를 사용하는 대신 Windows에서 코드가 작동하도록하려면 메소드에 전달 된 $ path 인수를 사용하십시오.

줄 대신 /vendor/magento/framework/View/Element/Template/File/Validator.php 경로로 이동하십시오.

if (0 === strpos($realPath, $directory)) {

사용하다

if (0 === strpos($path, $directory)) {

또는이 토론을 따르십시오 https://github.com/magento/magento2/issues/19480


2

Magento 2.2.9에서 /vendor/magento/framework/View/Element/Template/File/Validator.php isPathInDirectories 함수 코드를이 코드로 바꿉니다.

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

1

이것은 아마도 Windows 시스템에서 개발할 때 발생합니다.

Path /vendor/magento/framework/View/Element/Template/File/Validator.php 파일의 140 행으로 이동하십시오.

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

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

이 코드 줄을 조심하십시오

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

PHP 백 슬래시 풍경으로 인해 아마도 작동하지 않을 것입니다. PHP가 여기서 새 줄을 다루지 않고 백 슬래시를 처리한다고 명시 적으로 나타내려면 이중 백 슬래시를 수행해야합니다.


1

참조하십시오, 이중 슬래시 즉 "\\"

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

1

언급했듯이 문제는 Windows 호환성입니다. 그러나 Windows의 로컬 개발 및 Linux 서버의 나중에 배포와 같이 시스템을 마이그레이션하는 경우에도 작동하도록 약간 다르게 변경하는 것이 좋습니다. 따라서 Windows에서 작업하는 경우에만 경로를 조정하십시오.

\ vendor \ magento \ framework \ View \ Element \ Template \ 파일 \ Validator.php

isPathInDirectories () 함수

바꾸다

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

와:

a) PHP> = 7.2 :

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

b) PHP <7.2 :

if (strtolower(substr(PHP_OS, 0, 3)) === 'win')
  $realPath = str_replace('\\', '/', $this->fileDriver->getRealPath($path));
else
  $realPath = $this->fileDriver->getRealPath($path);
당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.