Havin 在 Zend 模块中遵循结构
模块名称
- 测试
- 配置
- 来源
- 查看
- 布局
- 测试
- 索引
- index.phtml
- 登录
- index.phtml
- 注册
- index.phtml
- 索引
- Module.php
现在以登录文件访问网站时,它将如下所示http://justsite.something.com/login
问题 需要改成http://justsite.something.com/login/为此,我在登录文件夹中添加了另一个文件夹索引,并像这样放置了 index.phtml 文件
- 登录
- 索引
- index.phtml
- 索引
但这似乎行不通。我是否应该更改 LoginController.php 才能使其正常工作?
module.confing.php
'router' => array(
'routes' => array(
'test' => array(
'type' => 'Literal',
'options' => array(
'route' => '/test',
'defaults' => array(
'__NAMESPACE__' =>'Test\Controller',
'controller' => 'Index',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'default' => array(
'type' => 'Segment',
'options' => array(
'route' =>
'/[:controller[/:action]]',
'constraints' => array(
'controller' =>
'[a-zA-Z][a-zA-Z0-9_-]*',
'action' =>
'[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(),
),
),
),
),
'login' => array(
'type' => 'Literal',
'options' => array(
'route' => '/login/', // PUT HERE WHATEVER YOU WANT
'defaults' => array( // AND MAP THAT URL TO CONTROLLER/ACTION
'__NAMESPACE__' =>'Test\Controller',
'controller' => 'Login',
'action' => 'index',
),
),
),
),
),
已修复刚刚添加
'may_terminate' => true,
'child_routes' => array(
'default' => array(
'type' => 'Segment',
'options' => array(
'route' =>
'/[:controller[/:action]/]',
最佳答案
就像@tasmaniski 写的那样,您不需要对 LoginController 或其他任何内容进行更改,一切都取决于您的路由配置。您不是唯一想要在他的 route “尾部斜线” 的人,here you can read how you can achieve this .
显然你需要把它放在 [] 之间
'route' => '/[:controller[/[:action[/]]]]',
希望这能为您解决。
注意 有些人建议为此使用重写规则,我认为这也值得一提。
关于php - Zend Framework 2 - route 的尾部斜杠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25480527/