php - Zend Framework 2 - route 的尾部斜杠

标签 php zend-framework2 directory-structure

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/

相关文章:

php - 向 PHP 发送动态数据

php - 什么时候需要与MySQLi绑定(bind)参数?

php - zend 框架 2 : How to create action in specific controller in specific action

php - Doctrine ZFA\排除字段显示在 IIS 上的表单上

Python 应用程序目录选择

python - 使用客户端和服务器部分构建 Python 应用程序

php - Yii2 QueryBuilder 更新与加入

php - 将 Mysql 结果转为 JSON 的数组

php - 如何在 Zend Framework2 上使用 PHP 通过 Doctrine 2 ODM 在 MongoDB 中执行查询?

javascript - 是否有存储 ReactJS Hook 文件的最佳实践?