0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Laminas (旧Zend fremework) MezzioのQuick Start

Last updated at Posted at 2021-06-11

レンダラーが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にアクセスすると・・・

レンダリングできないYo!

あれま。。。

修正

デフォルトではレンダラーがないのでTwigを追加してみます。

command
> composer require mezzio/mezzio-twigrenderer

すると今度は様子が変わる。

ディレクトリがないYo!

テンプレートディレクトリがないとのことなので、プロジェクトディレクトリの直下に
templates/app
templates/layout
templates/error
を作成し、appの下に
home-page.html.twig
というファイルをおきます。中身は"It Works!"とかでいいです。

オプションについて

「これ4」のところで[3]のlaminas-viewを選んでやると、きちんと出力されました。

見た目よし

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?