传递给Controller \ foo的参数1必须是Controller \ foo的实例

我是Zend Framework的新手。我在稳固的Zend教程网站(从A到Z)后面。我被困在这里..请帮助我


来自SO的一些解决方案没有太大帮助..确实做了什么,但是什么也没做。.与Zend Framework 2相同的帖子如下 :传递给Album \ Controller \ AlbumController :: __ construct()的参数1必须是Album \ Controller \ AlbumTable的实例


出现此错误


Argument 1 passed to Album\Controller\AlbumController::__construct() must be an instance of Album\Controller\AlbumTable, instance of Album\Model\AlbumTable given, called in C:\xampp\htdocs\zendF\module\Album\src\Module.php on line 43

我的Module.php


<?php

namespace Album;



use Zend\Db\Adapter\AdapterInterface;

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\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)

                    );

                },

            ],

        ];

    }

}

?>


Cats萌萌
浏览 116回答 1
1回答

翻过高山走不出你

您应该将依赖项放在名称空间之后。试试这个:<?php&nbsp; &nbsp; namespace Album\Controller;&nbsp; &nbsp; use Zend\Mvc\Controller\AbstractActionController;&nbsp; &nbsp; use Zend\View\Model\ViewModel;&nbsp; &nbsp; use Album\Model\AlbumTable;&nbsp; &nbsp; class AlbumController extends AbstractActionController&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; private $table;&nbsp; &nbsp; &nbsp; &nbsp; public function __construct(AlbumTable $table)&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $this->table = $table;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; public function indexAction() {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return new ViewModel([&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'albums' => $this->table->fetchAll(),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ]);&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; public function addAction() {&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; public function editAction() {&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; public function deleteAction() {&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }
打开App,查看更多内容
随时随地看视频慕课网APP