2017-09-16 123 views
1

在我的應用程序中,我在控制器中創建了第二個動作。當我通過網址http://local.domain調用應用程序時,我得到了正確的頁面,所以它被稱爲正確的控制器。但如果我想打這個電話http://local.domain/liga-futbol-1它不工作,我得到這個錯誤:ZF3:未找到動作和視圖

A 404 error occurred Page not found. The requested URL could not be matched by routing.

No Exception available

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', 
     ],   
    ], 
]; 

本公司歸屬的名錄:

enter image description here

我檢查我的緩存中的 「/ dir_project /數據/緩存」 並沒有什麼。

我在做什麼錯?

回答

3

看看home路線的route選項:它設置爲/。該liga-futbol-1路線是home路線的子路徑,因此它的網址是的「總和」:

  • 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-1開始route選項:

    'liga-futbol-1' => [ 
        'type' => Segment::class, 
        'options' => [ 
         'route' => 'liga-futbol-1', 
          'defaults' => [ 
           'controller' => Controller\IndexController::class, 
           'action'  => 'ligaFutbol1' 
          ] 
         ] 
        ] 
    
+0

它的工作原理!非常感謝你@gsc!一百萬的感謝! –