在null上调用成员函数fetchAll()

时间:2017-12-30 16:58:44

标签: mysql zend-framework2

错误:在null上调用成员函数fetchAll() 我基于这段代码:https://github.com/roggeo/zfblog

控制器:

 public function indexAction()
    {
        $users=$this->table->fetchAll();
       foreach ($users as $user){
           echo $user->getName().'<br/>';
       }
    }

连接到DB:

return [
    // ...
    'db'=>[
        'driver'=>'Pdo',
        'dsn'=>'mysql:dbname=blog;host=localhost;charset=utf8',
        'username'=>'root',
        'password'=>''
    ]
];

Class UserTable:

protected $tableGateway;
public function __construct(TableGatewayInterface $tableGateway)
{
    $this->tableGateway = $tableGateway;
}
public function fetchAll()
{
    return $this->tableGateway->select();
}

获取控制器配置:

 public function getControllerConfig(){
        return [
            'factories'=>[Controller\IndexController::class=>function($container){

                return new Controller\IndexController(
                    $container->get( Model\UserTable::class)
                );
            }]
        ];
    }

0 个答案:

没有答案