0

저는 ZF2 개발자이고 ZF3으로 마이그레이션 중이며 일부 컨트롤러에 문제가 있습니다.ZF3 : 자식 경로가있는 컨트롤러가 작동하지 않습니다.

예를 들어 올바른 컨트롤러 (IndexController)를 호출하고 올바른보기를 표시하는이 URL은 http://localhost/admin입니다. 하지만이 URL을 연관 시키려면 : http://localhos/admin/articulo과 ArticuloController가 작동하지 않습니다. 이 URL을 호출 할 때 : http://localhost/admin/articulo 호출 된 컨트롤러가 AdminController이고보기를 찾지 못합니다.

OPTION 1 => module.config.php :

namespace Admin; 

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

return [ 
    'router' => [ 
     'routes' => [ 
      'admin' => [ 
       'type' => Segment::class, 
       'options' => [ 
        'route' => '/admin[/:action]', 
        'defaults' => [ 
         'controller' => Controller\IndexController::class, 
         'action'  => 'index', 
        ], 
       ], 
      ], 
      'admin/articulos' => [ 
       'type' => Segment::class, 
       'options' => [ 
        'route' => '/admin/articulos[/:action]', 
        'defaults' => [ 
         'controller' => Controller\ArticulosController::class, 
         'action'  => 'index', 
        ], 
       ], 
      ],    
     ], 
    ], 
    'controllers' => [ 
     'factories' => [ 
      Controller\IndexController::class => InvokableFactory::class, 
      Controller\ArticulosController::class => InvokableFactory::class, 
     ], 
    ], 
    '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-admin.phtml', 
      'admin/index/index'  => __DIR__ . '/../view/admin/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', 
     ],   
    ], 
]; 

OPTION 2 => module.config.php (ZF2 스타일)

namespace Admin; 

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

return [ 
    'router' => [ 
     'routes' => [ 
      'admin' => [ 
       'type' => Segment::class, 
       'options' => [ 
        'route' => '/admin[/:action]', 
        'defaults' => [ 
         'controller' => Controller\IndexController::class, 
         'action'  => 'index', 
        ], 
       ], 
      ], 
      'admin/articulos' => [ 
       'type' => Literal::class, 
       'options' => [ 
        'route' => '/admin/articulos[/:action]', 
        'defaults' => [ 
         'controller' => 'Articulos', 
         'action'  => 'index', 
        ],     
       ], 
       'may_terminate' => true, 
       'child_routes' => [ 
        'default' =>[ 
         'type' => Segment::class, 
         'options' => [ 
          'route' => '/[:controller[/:action][/:id1]]', 
          'constraints' => [ 
           'controller' => '[a-zA-Z][a-zA-Z0-9_-]*', 
           'action'  => '[a-zA-Z][a-zA-Z0-9_-]*', 
           'id1'   => '[0-9_-]*' 
          ], 
          'defaults' => [], 
         ], 
        ], 
       ], 
      ],    
     ], 
    ], 
    'controllers' => [ 
     'factories' => [ 
      Controller\IndexController::class => InvokableFactory::class, 
      Controller\ArticulosController::class => InvokableFactory::class, 
     ], 
    ], 
    '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-admin.phtml', 
      'admin/index/index'  => __DIR__ . '/../view/admin/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', 
     ],   
    ], 
]; 

OPTION 3 = > module.config.php (zf3 자습서 다음) : https://docs.zendframework.com/zend-mvc/routing/#http-routing-examples

구성의 모든 내용은
namespace Admin; 

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

return [ 
    'router' => [ 
     'routes' => [ 
      'admin' => [ 
       'type' => Segment::class, 
       'options' => [ 
        'route' => '/admin[/:action]', 
        'defaults' => [ 
         'controller' => Controller\IndexController::class, 
         'action'  => 'index', 
        ], 
       ], 
       'may_terminate' => true, 
       'child_routes' => [ 
        'articulos' => [ 
         'type' => Segment::class, 
         'options' => [ 
          'route' => '/articulos[/:action]', 
          'defaults' => [ 
           'controller' => Controller\ArticulosController::class, 
           'action'  => 'index' 
          ], 
         ], 
        ], 
       ], 
      ],   
     ], 
    ], 
    'controllers' => [ 
     'factories' => [ 
      Controller\IndexController::class => InvokableFactory::class, 
      Controller\ArticulosController::class => InvokableFactory::class, 
     ], 
    ], 
    '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-admin.phtml', 
      'admin/index/index'  => __DIR__ . '/../view/admin/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', 
     ],   
    ], 
]; 

나는 URL을 호출 할 때 : http://localhost/admin/articulos I는 얻을보기 ... 당신이 전화 컨트롤러가 관리 \ 컨트롤러 \ 인 IndexController하고 있음을

enter image description here

를 볼 수있는 곳 아니 Admin \ Controller \ ArticulosController

내가 뭘 잘못하고있어?

업데이트 1 :

옵션 3 구성은 잘 작동! ... 나는 템플릿을 렌더링 이제 오류도 있고 ... 난 캐시 디렉토리 /에서 모든 내용을 삭제했으며 이제 컨트롤러가 발견 되나

메시지 :

젠드 \보기 \ 렌더러 \ PhpRenderer :: 렌더 : 템플릿을 렌더링 할 수 없습니다 "admin/articulos/index";

0 /var/www/html/31juegos/vendor/zendframework/zend-view/src/View.php(207) : 리졸버는 파일

스택 추적을 확인할 수 없습니다 : 젠드 \보기 \ 렌더러 \ PhpRenderer->) (

1 /var/www/html/31juegos/vendor/zendframework/zend-view/src/View.php(236 렌더링) : 젠드 \보기 \ 보기 -> 렌더링 (객체 (Zend \ View \ Model \ ViewModel))

2 /var/www/html/31juegos/vendor/zendframework/zend-view/src/View.php(200) : Zend \ View \ View-> renderChildren (Object (Zend \ View \ Model \ ViewModel))

3/var/www/html/31juegos/vendor/zendframework/zend-mvc/src /보기/Http/DefaultRenderingStrategy.PHP (105) :

젠드 \보기 \보기 -> 렌더링 (오브젝트 (젠드 \보기 \ 모델 \ 뷰 모델))

4의/var/www/html/31juegos/공급 업체/zendframework/젠드 - eventmanager로 /src/EventManager.php(322) : 젠드 \ MVC \보기 \ HTTP를 \ DefaultRenderingStrategy-> (오브젝트 (젠드 \ MVC \ MvcEvent))

5의/var/www/html/31juegos/공급 업체/zendframework 렌더링 /zend-eventmanager/src/EventManager.php(171) 젠드 \ 개의 EventManager \ EventManager-> triggerListeners (개체 (젠드 \ MVC \ MvcEvent))

6의/var/www/html/31juegos/벤더/zendframewo RK/젠드-MVC/SRC/Application.php (367) 젠드 \ 개의 EventManager \ EventManager-> 의해 triggerEvent (개체 (젠드 \ MVC \ MvcEvent))

7의/var/www/html/31juegos/벤더/zendframework/젠드-MVC/SRC/Application.php (348) : 젠드 \ MVC \ 응용 프로그램 -> completeRequest (오브젝트 (젠드 \ MVC \ MvcEvent))

8의/var/www/html/31juegos/공공/index.php를 (40) : 젠드 \ MVC \ 응용 프로그램 -> 실행()

9 {주}

enter image description here

+0

이 질문은 더 이상 재현 할 수없는 문제 또는 간단한 인쇄상의 오류로 인해 _ 생겼습니다. – halfer

답변

1

오타 문제입니다. 라우터 /admin/articulosArticulosControllerindexAction()을 가리키고 있기 때문에 http://localhost/admin/articulos (의 ""으로 끝나는 점을 유의하십시오)으로 시도하십시오. 그래서이 URL은 http://localhost/admin/articulo (의 ""을 끝내지 않고 보낼 수 없습니다. 뷰 구조는 module/controller/action이어야합니다.

+0

도움을 주셔서 감사합니다 !!! 하지만 http : // localhost/admin/articulos가 작동하지 않습니다. ( –

+0

http : // localhost/admin/articulos에서 여전히 동일한 오류가 발생합니까? – unclexo

+0

예. 처음 게시물에 더 많은 정보가 추가되었습니다. –

0

(게시자를 대신하여 게시 됨).

마지막으로 마지막 문제를 해결했습니다. 문제는 내 index.phtml이 잘못된 디렉토리 /view/admin/articulos/**index/**index.phtml에 있기 때문입니다. 올바른 디렉토리는 /view/admin/articulos/index.phtml입니다.

관련 문제