繁体   English   中英

ZF3:未找到操作和视图

[英]ZF3: Action and view doesn't found

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

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

没有例外

IndexController.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 [];
    } }

module.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”中检查了我的缓存,但没有任何内容。

我究竟做错了什么?

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

  • 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' ] ] ] 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM