1

在我的应用程序中,我在控制器中创建了第二个操作。当我使用 url http://local.domain调用应用程序时,我得到了正确的页面,因此它被称为正确的控制器。但是如果我想拨打这个电话http://local.domain/liga-futbol-1它不起作用,我有这个错误:

发生 404 错误页面未找到。请求的 URL 无法通过路由匹配。

没有可用的例外

索引控制器.php

namespace Stats\Controller;

use Zend\Mvc\Controller\AbstractActionController;

class IndexController extends AbstractActionController {
    public function indexAction()
    {
        //This action serves the page
        return [];
    }

    public function ligaFubtol1Action(){

        return [];
    } }

模块.config.php

namespace Stats;

use Zend\Router\Http\Segment;
use Zend\ServiceManager\Factory\InvokableFactory;

return [
    'controllers' => [
        'factories' => [
            Controller\IndexController::class => InvokableFactory::class,
        ],
    ],
    'router' => [
        'routes' => [
            'home' => [
                'type'    => 'Literal',
                'options' => [
                    // This works!!! => http://local.domain
                    'route'    => '/',
                    'defaults' => [
                        'controller'    => Controller\IndexController::class,
                        'action'        => 'index',
                    ],
                ],
                'may_terminate' => true,
                'child_routes' => [
                    // This doesn't work!!! http://local.domain/liga-futbol-1
                    'liga-futbol-1' =>  [
                        'type'  =>  Segment::class,
                        'options'   =>  [
                            'route' =>  '/liga-futbol-1',
                            'defaults'  =>  [
                                'controller'    => Controller\IndexController::class,
                                'action'        =>  'ligaFutbol1'
                            ],
                        ],
                        'may_terminate' =>  true,
                        'child_routes'  =>  [
                        ],
                    ],                    
                ],
            ],       
        ],
    ],
    'view_manager' => [
        'display_not_found_reason' => true,
        'display_exceptions'       => true,
        'doctype'                  => 'HTML5',
        'not_found_template'       => 'error/404',
        'exception_template'       => 'error/index',
        'template_map' => [
            'layout/layout'           => __DIR__ . '/../view/layout/layout.phtml',
            'stats/index/index'       => __DIR__ . '/../view/stats/index/index.phtml',
            'error/404'               => __DIR__ . '/../view/error/404.phtml',
            'error/index'             => __DIR__ . '/../view/error/index.phtml',
        ],
        'template_path_stack' => [
            __DIR__ . '/../view',
        ],
        /*
         * Con este array de parámetros permitimos enviar datos y no mostrar vista
         */
        'strategies' => [
            'ViewJsonStrategy',
        ],           
    ],
];

目录:

在此处输入图像描述

我在“/dir_project/data/cache”中检查了我的缓存,但什么也没有。

我究竟做错了什么?

4

1 回答 1

3

看看路线的route选项:它设置为. 该路由是该路由的子路由,因此其 URL 是以下各项的“总和”:home/liga-futbol-1home

  • home网址:/
  • liga-futbol-1网址:/liga-futbol-1

结果://liga-futbol-1home/liga-futbol-1路由的 URL。

如果你只想要类似的东西/liga-futbol-1,有两种解决方案:

  1. 使liga-futbol-1路线独立于home路线(即不是它的孩子):

    'routes' => [
        'home' => [
            'type' => Literal::class,
            'options' => [
                'route' => '/',
                'defaults' => [
                    'controller' => Controller\IndexController::class,
                    'action'     => 'index'
                ]
            ]
        ],
        'liga-futbol-1' => [
            'type' =>  Segment::class,
            'options' =>  [
                'route' => '/liga-futbol-1',
                'defaults' =>  [
                    'controller' => Controller\IndexController::class,
                    'action'     => 'ligaFutbol1'
                ]
            ]
        ]
    ]
    
  2. 从'选项/的开头删除:liga-futbol-1route

    'liga-futbol-1' =>  [
        'type' =>  Segment::class,
        'options' => [
            'route' => 'liga-futbol-1',
                'defaults' => [
                    'controller' => Controller\IndexController::class,
                    'action'     => 'ligaFutbol1'
                ]
            ]
        ]
    
于 2017-09-16T20:05:23.113 回答