Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [ZendFramework2][ZF2][inny]Wyświetlenie rezultatu zapytania z obiektu ResultSet
bebzon_hc
post
Post #1





Grupa: Zarejestrowani
Postów: 36
Pomógł: 1
Dołączył: 10.02.2011
Skąd: Rawicz

Ostrzeżenie: (0%)
-----


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.

Ten post edytował bebzon_hc 2.11.2016, 18:26:51
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 1)
hubson87
post
Post #2





Grupa: Zarejestrowani
Postów: 83
Pomógł: 8
Dołączył: 9.02.2011
Skąd: Wrocław

Ostrzeżenie: (0%)
-----


Spróbuj może http://php.net/manual/en/function.iterator-to-array.php
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 20.08.2025 - 20:19