1
私はいつもをデバッグしようとするとZF2に問題があります。["count":protected] => NULL
があります。私はtry/catch
をonBootstrap()
で使用してdb接続をチェックし、接続は問題ありません。また、私は依存のために私の工場クラスをチェックし、すべてがOKです!データベースでは、テーブルposts
に5つの項目がありますが、数はNULL
です。何が問題なのでしょうか?ZF2デバッグ結果セットカウントが返される
object(Zend\Db\ResultSet\ResultSet)#161 (8) {
["allowedReturnTypes":protected] => array(2) {
[0] => string(11) "arrayobject"
[1] => string(5) "array"
}
["arrayObjectPrototype":protected] => object(ArrayObject)#188 (1) {
["storage":"ArrayObject":private] => array(0) {
}
}
["returnType":protected] => string(11) "arrayobject"
["buffer":protected] => NULL
["count":protected] => NULL
["dataSource":protected] => object(Zend\Db\Adapter\Driver\Pdo\Result)#160 (9) {
["statementMode":protected] => string(7) "forward"
["fetchMode":protected] => int(2)
["resource":protected] => object(PDOStatement)#162 (1) {
["queryString"] => string(29) "SELECT `posts`.* FROM `posts`"
}
["options":protected] => NULL
["currentComplete":protected] => bool(false)
["currentData":protected] => NULL
["position":protected] => int(-1)
["generatedValue":protected] => string(1) "0"
["rowCount":protected] => NULL
}
["fieldCount":protected] => int(3)
["position":protected] => int(0)
}
マッパー:
public function __construct(AdapterInterface $adapterInterface)
{
$this->dbAdapter = $adapterInterface;
}
public function findAllPosts()
{
$sql = new Sql($this->dbAdapter);
$select = $sql->select('posts');
$stmt = $sql->prepareStatementForSqlObject($select);
$result = $stmt->execute();
if ($result instanceof ResultInterface && $result->isQueryResult()) {
$resultSet = new ResultSet();
\Zend\Debug\Debug::dump($resultSet->initialize($result));die();
}
die("no data");
}
工場:
class SqlPostMapperFactory
{
/**
* @param ServiceLocatorInterface $serviceLocatorInterface
* @return SqlPostMapper
*/
public function __invoke(ServiceLocatorInterface $serviceLocatorInterface)
{
return new SqlPostMapper(
$serviceLocatorInterface->get('Zend\Db\Adapter\Adapter')
);
}
}
local.phpファイル
return array(
'db' => array(
'driver' => 'Pdo',
'dsn' => 'mysql:dbname=zf2;host=localhost',
'username' => 'root',
'password' => '',
),
'service_manager' => array(
'factories' => array(
'Zend\Db\Adapter\Adapter' => 'Zend\Db\Adapter\AdapterServiceFactory',
),
),
);