ဖြေရှင်း “ဒါကအဆင်မပြေဖြစ်ပါသည် / 404 တွေ့မရအမှား” တပ်ဆင်ပြီးနောက် “Zend-ဖော်ပြ”

Middleware နှငျ့အလုပျလုပျ, ဒီပြဿနာကိုဖြေရှင်းနိုင်ပါလိမ့်မယ်တင်ရန် “ဒါကအဆင်မပြေဖြစ်ပါသည် / 404 တွေ့မရအမှား” တပ်ဆင်ပြီးနောက် “Zend-ဖော်ပြ”.

ပြဿနာ

Recentemente, interessado em ver como os Middleware funcionam, ငါ၏ installation ကိုပြု၏ “zend-expressive-skeletonconforme o Guia Quick Start: Using the Skeleton + Installer:

$ composer create-project zendframework/zend-expressive-skeleton expressive

ထိုနောက်မှ, para checar o resultado, acessei o navegador no endereço ကို http://localhost/expressive/public/ e peguei o seguinte erro:

Oops!
ဒါကအဆင်မပြေဖြစ်ပါသည်.
 
We encountered a 404 တွေ့မရအမှား.
 
You are looking ဘို့ something that doesn't exist or may have moved. Check out one of the links on this page or head back to Home.

ဖြေရှင်းနည်း

A mensagem de erro indicava que a página não tinha sido encontrada, ထိုကွောငျ့, parecia um problema de PATH (caminho) para os arquivos da aplicação.

Dando uma olhada por aí, cheguei a conclusão que isto aconteceu por eu não ter criado o projeto diretamente na raiz do diretório de publicação (ထွ: www/ ou htdocs/), mas em um subdiretório, desse jeito: ကို http://localhost/expressive/public/.

နောက်ဆုံးမှာ, parece que o Expressive tem alguma dificuldade com Base Url / Base Path. Na verdade a própria arquitetura do Zend Framework convenciona que o diretório de publicação deve ser opublic/“, tanto que se você rodar o servidor Web apontando parapublic/“, a aplicação funciona normalmente.

Rodando o comandophp -S 0.0.0.0:8080 -t public/pelo terminal (command):

Taylor@taylor-pc MINGW64 /c/wamp64/www/expressive
$ php -S 0.0.0.0:8080 -t public/
PHP 7.0.10 Development Server started at Thu Aug 10 15:55:00 2017
Listening on http://0.0.0.0:8080
Document root is C:\wamp64\www\expressive\public
Press Ctrl-C to quit.
[Thu Aug 10 15:55:34 2017] 127.0.0.1:65106 [404]: /expressive/public/

Agora sim, fazendo isto é possível acessar ကို http://localhost/expressive/public/ sem qualquer erro.

Mas para não ficar nessa de sempre apontar parapublic/“, existe o Middleware los/basepath como solução de contorno. installation ရိုးရှင်း:

$ composer require los/basepath

ထိုနောက်မှ, basta adicionar o Middleware como um dos primeiros na sua aplicação. ဥပမာအား, eu coloquei a chamada no arquivopublic\index.php”, logo após “$app ter sido inicializada:

1
$app->pipe(new \LosMiddleware\BasePath\BasePath('/expressive/public'));

That’s it!

Referência

Access /path/to/public got 404 page
Base Path Middleware for PHP

စုစုပေါင်း access: 569

Um comentário sobreဖြေရှင်း “ဒါကအဆင်မပြေဖြစ်ပါသည် / 404 တွေ့မရအမှား” တပ်ဆင်ပြီးနောက် “Zend-ဖော်ပြ”

တစ်ဦးစာပြန်ရန် Leave

သင့်အီးမေးလ်လိပ်စာပုံနှိပ်ထုတ်ဝေမည်မဟုတ်ပါ. တောင်းဆိုနေတဲ့လယ်ယာနှင့်အတူမှတ်သားထားတဲ့ *