Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [ZendFramework2][ZF2][inny]Wyświetlenie rezultatu zapytania z obiektu ResultSet
Forum PHP.pl > Forum > PHP > Frameworki
bebzon_hc
Witam!
Mam questa...

Na wstępie kod:

W MODELU
  1. public function fetchAll()
  2. {
  3. $resultSet = $this->tableGateway->select();
  4. return $resultSet;
  5. }


W KONTROLERZE
  1. public function indexAction()
  2. {
  3. $userTable = $this->getServiceLocator()->get('UserTable');
  4. $viewModel = new ViewModel(array('users' => $userTable->fetchAll()));
  5. return $viewModel;
  6. }


W WIDOKU
  1. var_dump($this->users);


REZULTAT VAR_DUMPA
  1. object(Zend\Db\ResultSet\ResultSet)#263 (8) {
  2. ["allowedReturnTypes":protected]=>
  3. array(2) {
  4. [0]=>
  5. string(11) "arrayobject"
  6. [1]=>
  7. string(5) "array"
  8. }
  9. ["arrayObjectPrototype":protected]=>
  10. object(Users\Model\User)#247 (4) {
  11. ["id"]=>
  12. NULL
  13. ["name"]=>
  14. NULL
  15. ["email"]=>
  16. NULL
  17. ["password"]=>
  18. NULL
  19. }
  20. ["returnType":protected]=>
  21. string(11) "arrayobject"
  22. ["buffer":protected]=>
  23. NULL
  24. ["count":protected]=>
  25. int(3)
  26. ["dataSource":protected]=>
  27. object(Zend\Db\Adapter\Driver\Pdo\Result)#262 (8) {
  28. ["statementMode":protected]=>
  29. string(7) "forward"
  30. ["resource":protected]=>
  31. object(PDOStatement)#253 (1) {
  32. ["queryString"]=>
  33. string(27) "SELECT `user`.* FROM `user`"
  34. }
  35. ["options":protected]=>
  36. NULL
  37. ["currentComplete":protected]=>
  38. bool(false)
  39. ["currentData":protected]=>
  40. NULL
  41. ["position":protected]=>
  42. int(-1)
  43. ["generatedValue":protected]=>
  44. string(1) "0"
  45. ["rowCount":protected]=>
  46. int(3)
  47. }
  48. ["fieldCount":protected]=>
  49. int(4)
  50. ["position":protected]=>
  51. int(0)
  52. }


I teraz pytanie smile.gif

Jak zrobić, żebym w widoku mógł posłigiwać się zwykłą tablicą? $resultSet zwraca obiekt typu ResultSet. Kiedy robię ->toArray(), rzutuję na array lub próbuję normalnego foreacha to zwraca błąd: Rows as part of this DataSource, with type object cannot be cast to an array.
hubson87
Spróbuj może http://php.net/manual/en/function.iterator-to-array.php
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.