我是zend framework2的新手。
我得到了错误。
An exception was raised while creating "UserTable"; no instance returned
。
请查看我的代码。
Login \ Model \ UserTable.php
protected $tableGateway;
public function __construct(TableGateway $tableGateway)
{
$this->tableGateway = $tableGateway;
}
public function fetchAll()
{
$resultSet = $this->tableGateway->select();
return $resultSet;
}
Login \ Module.php
public function getServiceConfig()
{
return array(
'factories' => array(
'UserTable' => function($serviceManager) {
$tableGateway = $serviceManager->get('UserTableGateway');
return new UserTable($tableGateway);
},
'UserTableGateway' => function ($serviceManager) {
$dbAdapter = $serviceManager->get('Zend\Db\Adapter\Adapter');
$resultSetPrototype = new ResultSet();
$resultSetPrototype->setArrayObjectPrototype(NULL);
return new TableGateway('user', $dbAdapter, NULL, $resultSetPrototype);
}
)
);
}
Login \ src \ Login \ Controller \ LoginController.php
public function getAction()
{
$serviceManager = $this->getServiceLocator();
$userTable = $serviceManager->get('UserTable');
$user = $userTable->fetchAll();
return $this->redirect()->toRoute('home', ['data' => $user]);
}
local.php
return array(
'db' => array(
'dsn' => 'mysql:dbname=album; host=localhost',
'username' => 'root',
'password' => 'root',
),
'service_manager' => array(
'factories' => array(
'Zend\Db\Adapter\Adapter'
=> 'Zend\Db\Adapter\AdapterServiceFactory',
),
)
);
当我刚重定向到控制器中getAction()
中的家时,它工作正常。
我无法解决这个问题。
有人可以帮我吗?
谢谢。
注意:如果需要更多详细信息,请发表评论。