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
<?php namespace Straz; // Add these import statements: use Straz\Model\Straz; use Straz\Model\StrazTableDanePer; use Zend\Db\ResultSet\ResultSet; use Zend\Db\TableGateway\TableGateway; class Module { public function getAutoloaderConfig() { __DIR__ . '/autoload_classmap.php', ), __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__, ), ), ); } public function getConfig() { return include __DIR__ . '/config/module.config.php'; } // getAutoloaderConfig() and getConfig() methods here // Add this method: // Add this method: public function getServiceConfig() { 'Straz\Model\StrazTableDanePer' => function (){ // $tabDanePer = $sm->get('Straz\Model\StrazTableDanePer'); $tabela = new StrazTableDanePer(); return $tabela; } ), ); } }
Model StrazTableDanePer.php
<?php namespace Straz\Model; use Zend\Db\TableGateway\TableGateway; use Zend\Db\Adapter\Adapter; class StrazTableDanePer { protected $adapter; protected $tablica; // public function __construct(TableGateway $bramaTabeli) // { // $this->bramaTabeli = $bramaTabeli; // } public function setAdapter() { 'driver' => 'Pdo_Mysql' , 'database' => 'straz' , 'username' => 'root' , 'passowrd' => '', ); $adapter = new Adapter($dbconfig); $this->adapter = $adapter; return $this->adapter; } public function tableGateway(){ $adapter = $this->setAdapter(); $this->tablica = new TableGateway('dane_per' , $adapter); return $this->tablica; } public function showAllTable(){ $this->tableGateway()->select(); } } // use Zend\Db\TableGateway\TableGateway; // $projectTable = new TableGateway('project', $adapter); // $rowset = $projectTable->select(array('type' => 'PHP')); // echo 'Projects of type PHP: '; // foreach ($rowset as $projectRow) { // echo $projectRow['name'] . PHP_EOL; // } // // or, when expecting a single row: // $artistTable = new TableGateway('artist', $adapter); // $rowset = $artistTable->select(array('id' => 2)); // $artistRow = $rowset->current(); // var_dump($artistRow);
StrazController.php
<?php namespace Straz\Controller; use Zend\Mvc\Controller\AbstractActionController; use Zend\View\Model\ViewModel; use Straz\Model\StrazTableDanePer; class StrazController extends AbstractActionController { protected $tabela; public function indexAction() { 'lista' => $this->getTable()->showAllTable(), )); } public function testAction() { } public function getTable() { if (!$this->tabela) { $sm = $this->getServiceLocator(); $this->tabela = $sm->get('Straz\Model\StrazTableDanePer'); } return $this->tabela; } }
I posty widok Index.phtml
<?php foreach ($lista as $dane) { } //echo "Test index ";