Zend framework2 传递给Application\Controller\IndexController::\uu construct()的参数1必须是Application\Model\EmployeeTable的实例,未给定任何实例

Zend framework2 传递给Application\Controller\IndexController::\uu construct()的参数1必须是Application\Model\EmployeeTable的实例,未给定任何实例,zend-framework2,Zend Framework2,我在Zd2中遇到了这个问题,在过去的两天里,我的头都撞到了,但没有找到任何解决方案。如果有人能帮我解决下面给出的错误,我将非常感激。 传递给Application\Controller\IndexController::\uu construct()的参数1必须是Application\Model\EmployeeTable的实例,未给定任何实例 这是我的应用程序模块配置文件Module.Config.php 名称空间应用 使用Zend\Router\Http\Literal;使用Zend\R

我在Zd2中遇到了这个问题,在过去的两天里,我的头都撞到了,但没有找到任何解决方案。如果有人能帮我解决下面给出的错误,我将非常感激。 传递给Application\Controller\IndexController::\uu construct()的参数1必须是Application\Model\EmployeeTable的实例,未给定任何实例

这是我的应用程序模块配置文件Module.Config.php

名称空间应用

使用Zend\Router\Http\Literal;使用Zend\Router\Http\Segment;使用 Zend\ServiceManager\Factory\InvokableFactory

返回[ [ “控制器”=>[ “可调用项”=>[ “应用程序\控制器\索引”=>“应用程序\控制器\索引控制器”, ], “工厂”=>[ '应用程序\控制器\索引'=>'应用程序\工厂\索引控制器工厂' ], ]

    ],
    'router' => [
    'routes' => [
        'home' => [
            'type' => Literal::class,
            'options' => [
                'route'    => '/',
                'defaults' => [
                    'controller' => Controller\IndexController::class,
                    'action'     => 'index',
                ],
            ],
        ],
        'application' => [
            'type'    => Segment::class,
            'options' => [
                'route'    => '/application[/:action]',
                'defaults' => [
                    'controller' => Controller\IndexController::class,
                    'action'     => 'index',
                ],
            ],
        ],
    ],
],
'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.phtml',
        'application/index/index' => __DIR__ . '/../view/application/index/index.phtml',
        'error/404'               => __DIR__ . '/../view/error/404.phtml',
        'error/index'             => __DIR__ . '/../view/error/index.phtml',
    ],
    'template_path_stack' => [
        __DIR__ . '/../view',
    ],
], ];
应用索引控制器

table=$table; } 公共函数索引(){ $view=新视图模型([ 'data'=>this->table->fetchAll(), ]); 返回$view; }}

Module.php文件

类模块实现ConfigProviderInterface{ 常量版本='3.0.3-dev'

public function getConfig()
{
    return include __DIR__ . '/../config/module.config.php';
}
public function getServiceConfig() {
    return  [
        'factories' => [
            Model\EmployeeTable::class => function ($container) {
                $tableGateway = $container>get(Model\EmployeeTableGateway::class);
                $table = new Model\EmployeeTable($tableGateway);
                return $table;
            },
            Model\EmployeeTableGateway::class => function ($container) {
                $dbAdapter = $container->get(AdapterInterface::class);
                $resultSetPrototype = new ResultSet();
                $resultSetPrototype->setArrayObjectPrototype(new Employee());
                return new TableGateway('employee', $dbAdapter, null, $resultSetPrototype);
            },
        ],
    ];
}
public function getControllerConfig() {
    return  [
        'factories' => [
            Controller\IndexController::class => function($container) {
                return new Controller\IndexController(
                    $container->get(EmployeeTable::class)
                );
            },
        ],
    ];
} }
模范员工

班级员工{ 公费$id; 公共$emp_名称; 公共部门$emp_工作; 公共函数exchangeArray($data){ $this->id=(!empty($data['id'])?$data['id']:null; $this->emp_name=(!empty($data['emp_name'])?$data['emp_name']:null; $this->emp_job=(!empty($data['emp_job'])?$data['emp_job']:null; }}

模范雇员表

使用Zend\Db\TableGateway\TableGateway; 使用Zend\Db\TableGateway\TableGateway接口

类别雇员表{ 受保护的网关; 公共函数uu构造(TableGatewayInterface$tableGateway){$this->tableGateway=$tableGateway;} 公共函数fetchAll(){ $resultSet=$this->tableGateway->select(); 返回$resultSet; }}


请帮助!

I在上面的Module.php中,或者在类的顶部编写

 use Model\EmployeeTable;
或者,将别名设置为
“Model\EmployeeTable::class”

public function getServiceConfig() {
        return  [
            'factories' => [
                Model\EmployeeTable::class => function ($container) {
                    $tableGateway = $container>get(Model\EmployeeTableGateway::class);
                    $table = new Model\EmployeeTable($tableGateway);
                    return $table;
                },
                Model\EmployeeTableGateway::class => function ($container) {
                    $dbAdapter = $container->get(AdapterInterface::class);
                    $resultSetPrototype = new ResultSet();
                    $resultSetPrototype->setArrayObjectPrototype(new Employee());
                    return new TableGateway('employee', $dbAdapter, null, $resultSetPrototype);
                },
            ],
            'aliases' => array(
                EmployeeTable::class => Model\EmployeeTable::class
            )
        ];
    }