2017-09-16 5 views
1

내 응용 프로그램에서 컨트롤러에서 두 번째 작업을 만들었습니다. URL이 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 경로의 하위 경로, 그래서 그 URL은의 "합"입니다 :

  • home URL : /
  • liga-futbol-1 URL : 결과에서 /liga-futbol-1

: //liga-futbol-1입니다 home/liga-futbol-1 경로입니다. 당신이 /liga-futbol-1 같은 뭔가를 원한다면, 두 가지 솔루션이

있습니다

'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' 
      ] 
     ] 
    ] 
] 
  • /을 제거

    1. home 경로의 liga-futbol-1 경로 독립적 인 (즉,하지 자식을) 확인 liga-futbol-1의 처음부터 route 옵션 :

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

    작품! 너무 고맙습니다. @ gsc !!! 백만 달러 감사합니다! –