2017-04-10 4 views
0

나는 같은 젠드 프레임 워크 2 튜토리얼 프로젝트의 오류,"서비스를 확인할 수 없습니다" "공장에, 당신은 당신이 구성 중에 제공 확신?" 젠드 프레임 워크에서 2

Unable to resolve service "Album\Controller\AlbumController" to a factory; are you certain you provided it during configuration? 

내 Module.php

namespace Album; 

use Zend\ModuleManager\Feature\ConfigProviderInterface; 

class Module implements ConfigProviderInterface 
{ 
public function getConfig() 
{ 
    return include __DIR__ . '/../config/module.config.php'; 
} 

public function getServiceConfig() 
{ 
    return [ 
     'factories' => [ 
      Model\AlbumTable::class => function($container) { 
       $tableGateway = $container->get(Model\AlbumTableGateway::class); 
       return new Model\AlbumTable($tableGateway); 
      }, 
      Model\AlbumTableGateway::class => function ($container) { 
       $dbAdapter = $container->get(AdapterInterface::class); 
       $resultSetPrototype = new ResultSet(); 
       $resultSetPrototype->setArrayObjectPrototype(new Model\Album()); 
       return new TableGateway('album', $dbAdapter, null, $resultSetPrototype); 
      }, 
     ], 
    ]; 
} 

public function getControllerConfig() 
{ 
    return [ 
     'factories' => [ 
      Controller\AlbumController::class => function($container) { 
       return new Controller\AlbumController(
        $container->get(Model\AlbumTable::class) 
       ); 
      }, 
     ], 
    ]; 
} 
} 

그리고 내 module.config.php이기 때문에 무엇입니까;

namespace Album; 

use Zend\Router\Http\Segment; 

//use Zend\ServiceManager\Factory\InvokableFactory; 

return [ 
'controllers' => [ 
    'factories' => [ 
     Controller\AlbumController::class => InvokableFactory::class, 
    ], 
], 

'router' => [ 
    'routes' => [ 
     'album' => [ 
      'type' => Segment::class, 
      'options' => [ 
       'route' => '/album[/:action[/:id]]', 
       'constraints' => [ 
        'action' => '[a-zA-Z][a-zA-Z0-9_-]*', 
        'id'  => '[0-9]+', 
       ], 
       'defaults' => [ 
        'controller' => Controller\AlbumController::class, 
        'action'  => 'index', 
       ], 
      ], 
     ], 
    ], 
], 

'view_manager' => [ 
    'template_path_stack' => [ 
     'album' => __DIR__ . '/../view', 
    ], 
], 
]; 

저는 Zend Framework에서 매우 새롭습니다. 내가 뭘 잘못하고 있는지 알아낼 수 없습니다. 더 많은 코드가 필요한지 언급하십시오.

당신은 "컨트롤러 \ AlbumController :: 클래스"에 대한 두 개의 공장을 정의

답변

1

...

module.config.php에서

한 -

return [ 
    'controllers' => [ 
     'factories' => [ 
      Controller\AlbumController::class => InvokableFactory::class, 
     ], 
    ], 
], 

및 Module.php-

에서 두 번째
public function getControllerConfig() 
{ 
    return [ 
     'factories' => [ 
      Controller\AlbumController::class => function($container) { 
       return new Controller\AlbumController(
        $container->get(Model\AlbumTable::class) 
       ); 
      }, 
     ], 
    ]; 
} 

그들은 모두 서로 충돌합니다. 호출 가능 팩토리는 의존성이없는 클래스 용입니다. "AlbumController"는 "AlbumTable"의 종속성이 같은 두 번째 옵션은 당신이 원하는 하나처럼 보이는이 경우 그것은, 보인다.

간단히 말해 module.config.php의 배열에서 '컨트롤러'키 값을 제거하십시오.

희망이 도움이됩니다.

+0

나는 그것을 가지고, 그 문제를 해결하지만, 새로운 서비스 "앨범 \를 해결할 수없는 **입니다 예 AdapterInterface "를 팩토리에; 당신은 당신이 구성 중에 제공? ** 지금 당신이 더 많은 나에게 좀 도와주세요 수있는 특정입니까? –

+0

config/modules.config.php 또는 config/application.config.php의 "modules"키에 zend \ db가 있습니까? –

+2

은 또한 당신이 필요합니다 "젠드 \ DB \ 어댑터 \ AdapterInterface를 사용합니다" in Module.php -> 이것은 당신의 문제로 보인다! –

2

나는 같은 문제와 몇 가지 다른 관련 문제를 가지고 있습니다. 나는 마침내 문제의 진정한 원천을 깨달았습니다. 내가 설치 한 것은 Zend 3입니다.

당신이 젠드 3이있는 경우

모든 수단 여기 젠드 3에 대한 자습서를 사용하여 : https://docs.zendframework.com/tutorials/getting-started/overview/

관련 문제