什么决定了 ZF2 中的视图文件夹结构?

What determines the view folder structure in ZF2?

是什么决定了 ZF2 中的视图文件夹结构?我按照 Album app 的初始 ZF2 教程进行操作,并注意到相册模块的视图位置在 /module/Album/view/album/album/*.phtml 中。

什么决定了 /album/album/ 部分?
为什么这些目录都是小写的?
为什么是同名嵌套?
在什么情况下它们会不一样?

我假设答案在 module.config.php 文件中。但是我尝试通过尝试将每个 album1 单独更改为 album1 来尝试与 album 的 3 个实例进行组合,以查看其效果。这是我的 module.config.php,每项更改的结果都在其旁边进行了注释。

return array(
    'controllers' => array(
        'invokables' => array(
            'Album\Controller\Album' => 'Album\Controller\AlbumController',
        ),
    ),

    // The following section is new and should be added to your file
    'router' => array(
        'routes' => array(
            'album' => array( //When switching to `album1` I get "Route with name "album" not found"
                              //If this is anything but `album` I get this error, regardless of the other 2 values.
                'type'    => 'segment',
                'options' => array(
                    'route'    => '/album[/:action][/:id]',    //When switching to `album1` I get "The requested URL could not be matched by routing."
                                                                //If I change my url to /album1 though, it works so long as the first is still `album`
                    'constraints' => array(
                        'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                        'id'     => '[0-9]+',
                    ),
                    'defaults' => array(
                        'controller' => 'Album\Controller\Album',
                        'action'     => 'index',
                    ),
                ),
            ),
        ),
    ),

    'view_manager' => array(
        'template_path_stack' => array(
            'album' => __DIR__ . '/../view',    //Changing this seems to have no effect.
                                                //I even changed this to `abc123` and it still worked while the other two instances were still `album`.
        ),
    ),
);

默认情况下,ZF 使用 /<module>/<controller>/<action>.phtml 查找视图。 'module'、'controller' 和 'action' 标准化为小写,驼峰式单词转换为破折号。

在您的示例中,单词 'album' 被重复,因为模块和控制器都被调用。如果您在相册模块中有一个 'tracks' 控制器,并且正在查看 'add' 操作,默认情况下 ZF 会在 /album/tracks/add.phtml.

中查找视图

至于为什么名字都转小写了,想不起来了。这可能是因为 PHP class/function 名称不区分大小写,可能是因为通常人们在 URL 中使用小写单词,或者可能只是因为通常这是人们在外部组织网站的方式构架。可能是这些东西的某种组合。