Last active
June 30, 2016 11:43
-
-
Save newage/5b4739a8f5a0c151ec9581fac2ba23e9 to your computer and use it in GitHub Desktop.
Zend Frameword 2 create a table factory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Album; | |
// Add these import statements: | |
use Album\Model\Album; | |
use Album\Model\AlbumTable; | |
use Zend\Db\ResultSet\ResultSet; | |
use Zend\Db\TableGateway\TableGateway; | |
class Module | |
{ | |
// getAutoloaderConfig() and getConfig() methods here | |
// Add this method: | |
public function getServiceConfig() | |
{ | |
return array( | |
'factories' => array( | |
'Users\Model\HelloTable' => function($sm) { | |
$tableGateway = $sm->get('AlbumTableGateway'); | |
$table = new HelloTable($tableGateway); | |
return $table; | |
}, | |
'AlbumTableGateway' => function ($sm) { | |
$dbAdapter = $sm->get('Zend\Db\Adapter\Adapter'); | |
$resultSetPrototype = new ResultSet(); | |
$resultSetPrototype->setArrayObjectPrototype(new Album()); | |
return new TableGateway('album', $dbAdapter, null, $resultSetPrototype); | |
}, | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment