You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Zend Framework 3:FournitureTable服务无法解析为工厂的问题求助

Fixing "Unable to resolve service Fourniture\Model\FournitureTable to a factory" in Zend Framework 3

Hey there! No worries at all about your English or being new to ZF3/Stack Overflow—let's fix that error together. 😊

The Root Cause

You've registered your FournitureTableFactory under the controllers > factories section of your module.config.php, but in Zend Framework 3, service factories (like database table classes) need to be registered in the service_manager configuration key instead. The container is looking for your table's factory in the wrong place, hence the error.

Corrected module.config.php

Update your configuration to move the FournitureTable factory to the service_manager section, like this:

<?php
use Fourniture\Model\FournitureTable;
use Fourniture\Controller\FournitureController;
use Fourniture\Factory\FournitureControllerFactory;
use Fourniture\Model\Factory\FournitureTableFactory;
use Zend\Router\Http\Segment;

return [
    'controllers' => [
        'factories' => [
            Fourniture\Controller\FournitureController::class => Fourniture\Factory\FournitureControllerFactory::class,
            // Removed FournitureTable factory from here!
        ],
    ],
    // Add this service_manager section to register your table factory
    'service_manager' => [
        'factories' => [
            Fourniture\Model\FournitureTable::class => Fourniture\Model\Factory\FournitureTableFactory::class,
        ],
    ],
    'view_manager' => [
        'template_path_stack' => [
            'fourniture' => __DIR__ . '/../view',
            __DIR__ . '/../view',
        ],
    ],
];
?>

Quick Check for Your Controller Factory

Make sure your FournitureControllerFactory correctly retrieves the FournitureTable service from the container. It should look something like this:

<?php
namespace Fourniture\Factory;

use Fourniture\Controller\FournitureController;
use Fourniture\Model\FournitureTable;
use Interop\Container\ContainerInterface;
use Zend\ServiceManager\Factory\FactoryInterface;

class FournitureControllerFactory implements FactoryInterface
{
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
    {
        // Fetch the FournitureTable service from the container
        $fournitureTable = $container->get(FournitureTable::class);
        
        // Pass it to the controller constructor
        return new FournitureController($fournitureTable);
    }
}
?>

Extra Notes

  • Ensure your Fourniture model class has all the necessary properties and a matching exchangeArray method (since you're using ResultSet with an ArrayObjectPrototype—this is required to map database rows to your model object).
  • Double-check all namespace references are correct (your existing code looks good here, but it's easy to mix these up when starting out!).

内容的提问来源于stack exchange,提问作者Rlecomte

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 04:52:44