d.l*_*a38 1 php zend-framework routes zend-framework2
是什么决定了ZF2中的视图文件夹结构?我使用Album应用程序跟踪了最初的ZF2教程,并注意到相册模块的视图位置/module/Album/view/album/album/*.phtml
.
是什么决定了这一/album/album/
部分?
为什么这些目录都是小写的?
为什么嵌套的名字相同?
在什么情况下他们会不一样?
我假设答案在module.config.php
文件中.但是我尝试使用3个实例的组合album
来尝试将每个实例album1
单独更改以查看其具有的效果.这是我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`.
),
),
);
Run Code Online (Sandbox Code Playgroud)
默认情况下,ZF使用查找视图/<module>/<controller>/<action>.phtml
.'module','controller'和'action'被归一化为小写,将camel cased单词转换为破折号.
在您的示例中,重复"专辑"一词,因为模块和控制器都被调用.如果您在相册模块中有"曲目"控制器,并且正在查看"添加"操作,则默认情况下ZF会查找该视图/album/tracks/add.phtml
.
至于为什么名称被转换为小写,我不记得了.这可能是因为PHP类/函数名称不区分大小写,可能是因为人们通常在URL中使用小写单词,或者可能只是因为这通常是人们在框架之外组织网站的方式.可能是这些东西的某种组合.