1
期間提供這麼即時努力學習Zend框架3,我對這個錯誤現在stucking因爲時間:ZF3介紹博客模塊,你肯定你的配置
Unable to resolve service "Blog\Controller\ListController" to a factory; are
you certain you provided it during configuration?
我從學習教程: https://docs.zendframework.com/tutorials/in-depth-guide/models-and-servicemanager/
本教程在「編寫工廠類」這一點上說,預計會出現此錯誤消息,但在「註冊服務」中它應該得到修復,但它不會。
我module.config.php:
<?php
namespace Blog;
use Zend\Config\Factory;
use Zend\Router\Http\Literal;
use Zend\ServiceManager\Factory\InvokableFactory;
return [
'service_manager' => [
'aliases' => [
Model\PostRepositoryInterface::class => Model\PostRepository::class,
],
'factories' => [
Model\PostRepository::class => InvokableFactory::class,
],
],
'controllers' => [
'factories' => [
// Update the following line:
Controller\ListController::class =>
Factory\ListControllerFactory::class,
],
],
'router' => [
'routes' => [
'blog' => [
'type' => Literal::class,
'options' => [
'route' => '/blog',
'defaults' => [
'controller' => Controller\ListController::class,
'action' => 'index',
],
],
],
],
],
'view_manager' => [
'template_path_stack' => [
__DIR__ . '/../view',
],
],
];
我ListController.php:
namespace Blog\Controller;
use Blog\Model\PostRepositoryInterface;
use Zend\Mvc\Controller\AbstractActionController;
class ListController extends AbstractActionController
{
/**
* @var PostRepositoryInterface
*/
private $postRepository;
public function __construct(PostRepositoryInterface $postRepository)
{
$this->postRepository = $postRepository;
}
}
喜多利,首先感謝您的回答和我的遲到一個遺憾。其實,我已經創建了一個ListControllerFactory但有不同的回報: '公共職能__invoke(ContainerInterface $容器,$ requestedName,數組$選項= NULL){ 返回 新ListController($容器 - >獲取(PostRepositoryInterface ::類)); }' – Kden
沒問題,我認爲回報是一樣的。因爲您使用「別名」名稱進行訪問。那麼,你是否仍然遇到問題? –
是的,仍然是同樣的問題。 – Kden