レンダラーがTwigのとき, Quick Startが動かない
Quick StartのスケルトンコードがレンララーにTwigを選択したときには動かなかったので色々やってみました。Windows上でPHP7.4がコマンドラインで使えて、かつcomposerが使える環境でやっています。
設定
適当なフォルダを作って、そこで上記ページにあるcomposerのコマンドを実行します。
command
> composer create-project mezzio/mezzio-skeleton mezzio
色々聞かれますが、リターンしていくと、こんな感じになります。
command
What type of installation would you like?
[1] Minimal (no default middleware, templates, or assets; configuration only)
[2] Flat (flat source code structure; default selection) <<<これ1
[3] Modular (modular source code structure; recommended)
Make your selection (2):
Which container do you want to use for dependency injection?
[1] Aura.Di (supported by laminas)
[2] Pimple (supported by laminas)
[3] laminas-servicemanager (supported by laminas) <<<これ2
[4] Auryn
[5] Symfony DI Container
[6] PHP-DI
[7] chubbyphp-container
Make your selection or type a composer package name and version (laminas-servicemanager (supported by laminas)):
Which router do you want to use?
[1] Aura.Router (supported by laminas)
[2] FastRoute (supported by laminas) <<<これ3
[3] laminas-router (supported by laminas)
Make your selection or type a composer package name and version (FastRoute (supported by laminas)):
Which template engine do you want to use?
[1] Plates (supported by laminas)
[2] Twig (supported by laminas)
[3] laminas-view installs laminas-servicemanager (supported by laminas)
[n] None of the above <<<これ4
Make your selection or type a composer package name and version (n):
Which error handler do you want to use during development?
[1] Whoops (supported by laminas) <<<これ5
[n] None of the above
Make your selection or type a composer package name and version (Whoops (supported by laminas)):
Please select which config file you wish to inject 'Laminas\Validator\ConfigProvider' into:
[0] Do not inject
[1] config/config.php <<<これ6
Make your selection (default is 1):
Remember this option for other packages of the same type? (Y/n)
その後mezzioディレクトリに入って
command
> composer run --timeout=86400 serve
を実行してプラウザでlocalhost:8080にアクセスすると・・・
あれま。。。
修正
デフォルトではレンダラーがないのでTwigを追加してみます。
command
> composer require mezzio/mezzio-twigrenderer
すると今度は様子が変わる。
テンプレートディレクトリがないとのことなので、プロジェクトディレクトリの直下に
templates/app
templates/layout
templates/error
を作成し、appの下に
home-page.html.twig
というファイルをおきます。中身は"It Works!"とかでいいです。
オプションについて
「これ4」のところで[3]のlaminas-viewを選んでやると、きちんと出力されました。