zend - 功能参数太少

时间:2018-05-16 07:32:32

标签: php zend-framework backend

indexcontroller.php代码中

namespace Application\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;

class IndexController extends AbstractActionController
{
    protected $table;

    public function __construct($table)
    {
        $this->table=$table;
    }

    public function indexAction()
    {

        $users=$this->table->fetchall();

        foreach($users as $user){


            echo $user->getName().'<br/>';

        }

        exit;

        return new ViewModel();
    }

}

这是我的module.php文件代码

namespace Application;

use Zend\Db\Adapter\AdapterInterface;
use Zend\Db\TableGateway\TableGateway;
use Zend\Db\ResultSet\ResultSet;
use Zend\ModuleManager\Feature\ConfigProviderInterface;

class Module implements ConfigProviderInterface
{

    const VERSION = '3.0.3-dev';

    public function getConfig()
    {
        return include __DIR__ . '/../config/module.config.php';
    }

    public function getServiceConfig()
    {
        return [
        'factories'=>[
        Model\UserTable::class=>function($container){
            $tableGateway=$container->get(Model\UserTableGateway::class);
            return new MOdel\UserTable($tableGateway);
        },
        Model\UserTableGateway::class=>function($container){
            $adapter=$container->get(AdapterInterface::class);
            $resultSetPrototype=new ResultSet();
            $resultSetPrototype->setArrayObjectPrototype(new Model\User);
            return new TableGateway('user', $adapter, null, $resultSetPrototype);
        }
        ]
        ];


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

}
}

运行此代码时会显示如下错误:

文件:

C:\xampp\htdocs\ZEND\ZendSkeletonApplication-master\module\Application\src\Controller\IndexController.php:17

消息:

  

功能参数太少   Application \ Controller \ IndexController :: __ construct(),传入0   C:\ XAMPP \ htdocs中\ ZEND \ ZendSkeletonApplication主\厂商\ zendframework \ Zend的-的ServiceManager \ SRC \厂\ InvokableFactory.php   第30行,正好是预期的

有人可以帮我解决这个问题吗?

由于

1 个答案:

答案 0 :(得分:0)

在你的module.php文件中,MOdel应该是Model。

public function getServiceConfig()
    {
        return [
        'factories'=>[
        Model\UserTable::class=>function($container){
            $tableGateway=$container->get(Model\UserTableGateway::class);
            **return new MOdel\UserTable($tableGateway);**
        },
        Model\UserTableGateway::class=>function($container){
            $adapter=$container->get(AdapterInterface::class);
            $resultSetPrototype=new ResultSet();
            $resultSetPrototype->setArrayObjectPrototype(new Model\User);
            return new TableGateway('user', $adapter, null, $resultSetPrototype);
        }
        ]
        ];
}