加载中...

7.2 添加模块文件


添加文件:/module/Album/Module.php,内容如下:

  1. namespace Album;
  2. use Album\Model\Album;
  3. use Album\Model\AlbumTable;
  4. use Zend\Db\ResultSet\ResultSet;
  5. use Zend\Db\TableGateway\TableGateway;
  6. class Module{
  7. public function getAutoloaderConfig(){
  8. return array(
  9. 'Zend\Loader\StandardAutoloader'=>array(
  10. 'namespaces'=>array(
  11. __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
  12. ),
  13. ),
  14. );
  15. }
  16. public function getConfig(){
  17. return include __DIR__ . '/config/module.config.php';
  18. }
  19. public function getServiceConfig()
  20. {
  21. return array(
  22. 'factories'=>array(
  23. 'Album\Model\AlbumTable'=>function($sm){
  24. $tg = $sm->get('AlbumTableGateway');
  25. $table = new AlbumTable($tg);
  26. return $table;
  27. },
  28. 'AlbumTableGateway'=>function($sm){
  29. $adapter = $sm->get('Zend\Db\Adapter\Adapter');
  30. $rs = new ResultSet();
  31. $rs->setArrayObjectPrototype(new Album());
  32. return new TableGateway('album',$adapter,null,$rs);
  33. }
  34. ),
  35. );
  36. }
  37. }

代码简单解释:

public function getAutoloaderConfig(){} 配置文件加载路径

public function getConfig(){} 获取模块配置文件

public function getServiceConfig(){} 获取模块服务配置信息


还没有评论.