亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

傳遞給Controller \ foo的參數1必須是Controller \ foo的實例

傳遞給Controller \ foo的參數1必須是Controller \ foo的實例

PHP
Cats萌萌 2021-04-09 17:19:02
我是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<?phpnamespace 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)                    );                },            ],        ];    }}?>
查看完整描述

1 回答

?
翻過高山走不出你

TA貢獻1875條經驗 獲得超3個贊

您應該將依賴項放在名稱空間之后。

試試這個:


<?php


    namespace Album\Controller;


    use Zend\Mvc\Controller\AbstractActionController;

    use Zend\View\Model\ViewModel;

    use Album\Model\AlbumTable;


    class AlbumController extends AbstractActionController

    {


        private $table;


        public function __construct(AlbumTable $table)

        {

            $this->table = $table;

        }


        public function indexAction() {

            return new ViewModel([

                'albums' => $this->table->fetchAll(),

            ]);

        }


        public function addAction() {

        }


        public function editAction() {

        }


        public function deleteAction() {

        }

    }


查看完整回答
反對 回復 2021-04-23
  • 1 回答
  • 0 關注
  • 129 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號