Witam
Uczę się zawzięcie ZF2 lecz nie wszystko ogarniam. Problem prawdo podobnie polega zna złej konfiguracji w pliku Module.php gdyż napisałem kontroler, model i prosty widok.
Niestety tablica przy wyświetlaniu jest pusta.
Będę wdzięczny za podpowiedzi.

Module.php
  1. <?php
  2. namespace Straz;
  3.  
  4. // Add these import statements:
  5. use Straz\Model\Straz;
  6. use Straz\Model\StrazTableDanePer;
  7. use Zend\Db\ResultSet\ResultSet;
  8. use Zend\Db\TableGateway\TableGateway;
  9.  
  10.  
  11. class Module
  12. {
  13. public function getAutoloaderConfig()
  14. {
  15. return array(
  16. 'Zend\Loader\ClassMapAutoloader' => array(
  17. __DIR__ . '/autoload_classmap.php',
  18. ),
  19. 'Zend\Loader\StandardAutoloader' => array(
  20. 'namespaces' => array(
  21. __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
  22. ),
  23. ),
  24. );
  25. }
  26.  
  27. public function getConfig()
  28. {
  29. return include __DIR__ . '/config/module.config.php';
  30. }
  31.  
  32. // getAutoloaderConfig() and getConfig() methods here
  33. // Add this method:
  34.  
  35.  
  36. // Add this method:
  37. public function getServiceConfig()
  38. {
  39. return array(
  40. 'factories' => array(
  41. 'Straz\Model\StrazTableDanePer' => function (){
  42. // $tabDanePer = $sm->get('Straz\Model\StrazTableDanePer');
  43. $tabela = new StrazTableDanePer();
  44. return $tabela;
  45. }
  46. ),
  47. );
  48.  
  49. }
  50.  
  51. }
  52.  



Model StrazTableDanePer.php

  1. <?php
  2. namespace Straz\Model;
  3.  
  4. use Zend\Db\TableGateway\TableGateway;
  5. use Zend\Db\Adapter\Adapter;
  6.  
  7. class StrazTableDanePer
  8. {
  9.  
  10. protected $adapter;
  11. protected $tablica;
  12.  
  13. // public function __construct(TableGateway $bramaTabeli)
  14. // {
  15. // $this->bramaTabeli = $bramaTabeli;
  16. // }
  17.  
  18.  
  19. public function setAdapter() {
  20. $dbconfig = array(
  21. 'driver' => 'Pdo_Mysql' ,
  22. 'database' => 'straz' ,
  23. 'username' => 'root' ,
  24. 'passowrd' => '',
  25. );
  26. $adapter = new Adapter($dbconfig);
  27. $this->adapter = $adapter;
  28. return $this->adapter;
  29. }
  30.  
  31.  
  32.  
  33. public function tableGateway(){
  34. $adapter = $this->setAdapter();
  35. $this->tablica = new TableGateway('dane_per' , $adapter);
  36. return $this->tablica;
  37. }
  38.  
  39.  
  40.  
  41.  
  42. public function showAllTable(){
  43. $this->tableGateway()->select();
  44.  
  45. }
  46.  
  47.  
  48. }
  49.  
  50.  
  51. // use Zend\Db\TableGateway\TableGateway;
  52. // $projectTable = new TableGateway('project', $adapter);
  53. // $rowset = $projectTable->select(array('type' => 'PHP'));
  54.  
  55. // echo 'Projects of type PHP: ';
  56. // foreach ($rowset as $projectRow) {
  57. // echo $projectRow['name'] . PHP_EOL;
  58. // }
  59.  
  60. // // or, when expecting a single row:
  61. // $artistTable = new TableGateway('artist', $adapter);
  62. // $rowset = $artistTable->select(array('id' => 2));
  63. // $artistRow = $rowset->current();
  64.  
  65. // var_dump($artistRow);



StrazController.php
  1. <?php
  2. namespace Straz\Controller;
  3.  
  4. use Zend\Mvc\Controller\AbstractActionController;
  5. use Zend\View\Model\ViewModel;
  6. use Straz\Model\StrazTableDanePer;
  7.  
  8.  
  9. class StrazController extends AbstractActionController
  10. {
  11.  
  12. protected $tabela;
  13.  
  14. public function indexAction()
  15. {
  16. return new ViewModel(array(
  17. 'lista' => $this->getTable()->showAllTable(),
  18. ));
  19. }
  20.  
  21. public function testAction()
  22. {
  23.  
  24. }
  25.  
  26. public function getTable()
  27. {
  28. if (!$this->tabela) {
  29. $sm = $this->getServiceLocator();
  30. $this->tabela = $sm->get('Straz\Model\StrazTableDanePer');
  31. }
  32. return $this->tabela;
  33. }
  34. }
  35.  


I posty widok Index.phtml
  1. <?php
  2.  
  3.  
  4. var_dump($lista);
  5. foreach ($lista as $dane) {
  6.  
  7.  
  8. echo $dane['imie'];
  9. }
  10.  
  11.  
  12. //echo "Test index ";