0

我是 Zend Fw 3 的新手。我遵循https://docs.zendframework.com/tutorials/ 我在 module.php 中添加了控制器配置

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

通过运行这个,我遇到了这个错误:

错误

4

2 回答 2

0

尝试执行AutoloaderProviderInterface如下:

<?php

namespace Document;

use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\TableGateway;
use Zend\ModuleManager\Feature\ConfigProviderInterface;
use Zend\ModuleManager\Feature\AutoloaderProviderInterface;

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

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

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

   public function getAutoloaderConfig()
   {
       return [
           'Zend\Loader\StandardAutoloader' => [
               'namespaces' => [
                   __NAMESPACE__ => __DIR__,
               ],
           ],
       ];
   }
}

您可能需要更改行中的路径__NAMESPACE__ => __DIR__,具体取决于您使用的目录结构和Module.php文件的位置。

于 2017-02-25T19:18:06.560 回答
0
<?php
     namespace Document;

     use Zend\Db\ResultSet\ResultSet;
     use Zend\Db\TableGateway\TableGateway;
     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\DocumentTable::class => function($container) {
                            $tableGateway = $container->get(Model\DocumentTableGateway::class);
                            return new Model\DocumentTable($tableGateway);
                        },
                        Model\DocumentTableGateway::class => function ($container) {
                            $dbAdapter = $container->get(AdapterInterface::class);
                            $resultSetPrototype = new ResultSet();
                            $resultSetPrototype->setArrayObjectPrototype(new Model\Document());
                            return new TableGateway('document', $dbAdapter, null, $resultSetPrototype);
                        },
                ],
           ];
        }

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

}
于 2017-02-25T11:30:48.420 回答