0

私はこのチュートリアルに取り組んでいます。ディレクトリ構造、コントローラー、module.php、module.config.phpを作成するためのすべての手順を実行しましたが、開くhttp://zf2-tutorial/albumと次のエラーが発生します。

 Fatal error: Uncaught exception 'Zend\View\Exception\RuntimeException' with message 'Zend\View\Renderer\PhpRenderer::render: Unable to render template "album/album/index"; resolver could not resolve to a file' in /var/www/zf2-tutorial/vendor/zendframework/zendframework/library/Zend/View/Renderer/PhpRenderer.php:461

index.phtmlview / album/albumディレクトリのモジュールディレクトリ内に名前の付いたファイルを作成しました。

module.config.php

return array(
    'controllers' => array(
        'invokables' => array(
            'Album\Controller\Album' => 'Album\Controller\AlbumController',       
        ),
        'view_manager' => array(
            'template_map' => array(
            'layout/layout'           => __DIR__ . '/../view/layout/layout.phtml',
            'album/album/index' => __DIR__ . '/../view/album/album/index.phtml',
            'error/404'               => __DIR__ . '/../view/error/404.phtml',
            'error/index'             => __DIR__ . '/../view/error/index.phtml',
                ),
            'template_path_stack' => array(
                'album' => __DIR__ . '/../view',
            )
        )
    ),

    'router' => array(
        'routes' => array(
            'album' => array(
                'type'    => 'segment',
                'options' => array(
                    'route'    => '/album[/:action][/:id]',
                    'constraints' => array(
                        'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                        'id'     => '[0-9]+',
                    ),
                    'defaults' => array(
                        'controller' => 'Album\Controller\Album',
                        'action'     => 'index',
                    ),
                ),
            ),
        ),
    ),

);

どうしたの?

4

12 に答える 12

6

ビュー phtml ファイルが見つからないため、PhpRenderer オブジェクトが不平を言っています。

ファイルmodule/Album/view/album/album/index.phtmlは存在しますか?そうでない場合は、それが原因である可能性があります。

于 2012-12-06T16:40:23.823 に答える
2

私は同じ問題に直面しました。ファイルmodule.config.phpの以下の行を変更しました。ドキュメントに存在します。

'view_manager' => array(
  'template_path_stack' => array(
  'album' => __DIR__ . '/../view',
  ),
),

'view_manager' => array(
  'template_path_stack' => array(
  'album' => __DIR__ . '/../src/view',
  ),
),

ビューフォルダーの前にsrcフォルダー名を追加するだけです。

このように、すべてのビュー パスの前に「src」フォルダー名を追加する必要があります。

于 2013-09-17T14:22:18.263 に答える
1

次のようにviewオブジェクトを返す必要がありますIndexController

$view = new ViewModel(array('albums' => $this->getAlbumTable()->fetchAll(),));
$view->setTemplate("album/album/index/index.phtml");
return $view;

直接戻るのではなく

return array('albums' => $this->getAlbumTable()->fetchAll(),);
于 2015-01-27T09:05:09.560 に答える
0

Albumモジュールであなたのコードをチェックしました。すべて順調。htaccess ファイルに問題がある可能性があります。チェックしてください。

于 2013-01-04T12:12:16.120 に答える
0

view_manager が間違った場所にあります。「コントローラー」内ではなく、「コントローラー」および「ルーター」レベルにある必要があります。Application モジュールの module.config.php を見て、違いを確認してください。

于 2013-04-16T13:14:29.157 に答える
0

「アルバム」ではなく「アルバム」の場合は、application.config.php モジュール名を確認してください。

'template_path_stack' => array(
    'album' => __DIR__ . '/../view', => //to 'Album' => __DIR__ . '/../view',
),
于 2016-08-18T19:56:48.553 に答える
0

module.config.phpview_manager内にあるtemplate_map配列では、バックスラッシュではなくスラッシュを使用してください。

于 2013-06-20T06:34:07.737 に答える