加载中...

7.2 添加模块文件


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

namespace Album;
use Album\Model\Album;
use Album\Model\AlbumTable;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\TableGateway;
class Module{
    public function getAutoloaderConfig(){
        return array(
            'Zend\Loader\StandardAutoloader'=>array(
                'namespaces'=>array(
                    __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
                ),
            ),
        );
    }

    public function getConfig(){
        return include __DIR__ . '/config/module.config.php';
    }

    public function getServiceConfig()
    {
        return array(
            'factories'=>array(
                'Album\Model\AlbumTable'=>function($sm){
                    $tg = $sm->get('AlbumTableGateway');
                    $table = new AlbumTable($tg);
                    return $table;
                },
                'AlbumTableGateway'=>function($sm){
                    $adapter = $sm->get('Zend\Db\Adapter\Adapter');
                    $rs = new ResultSet();
                    $rs->setArrayObjectPrototype(new Album());
                    return new TableGateway('album',$adapter,null,$rs);
                }
            ),
        );
    }

}

代码简单解释:

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

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

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


还没有评论.