php - 如何创建其他连接 zf2 apigility?

标签 php mysql zend-framework2 laminas-api-tools

如何创建到我的 data/database.db 的连接 我仅通过一个配置获得此连接,但不能从同一文件 module.php

中的另一个配置获得此连接

在这段代码中就可以了

public function getServiceConfig()
    {
        return array(
                'factories' => array(

                            'Music\V1\Rest\Album\AlbumMapper' =>  function ($sm) {
                            $adapter = $sm->get('Zend\Db\Adapter\Adapter');
                            return new \Music\V1\Rest\Album\AlbumMapper($adapter);
                            },
                ),
        );
    }

但是如果我尝试使用两个连接不起作用:

   public function getServiceConfig()
    {
        return array(
                'factories' => array(

                            'Music\V1\Rest\Album\AlbumMapper' =>  function ($sm) {
                            $adapter = $sm->get('Zend\Db\Adapter\Adapter');
                            return new \Music\V1\Rest\Album\AlbumMapper($adapter);
                            },


                            'Music\V1\Rest\Albumjson\AlbumjsonMapper' =>  function ($sm) {
                            $adapter = $sm->get('Zend\Db\Adapter\Adapter');
                            return new \Music\V1\Rest\Albumjson\AlbumjsonMapper($adapter);
                          },

                ),
        );
    }

我得到next error with zf2 :

An abstract factory could not create an instance of musicv1restalbumjsoncontroller(alias: Music\\V1\\Rest\\Albumjson\\Controller).

最佳答案

该错误与您的数据库设置无关。这意味着找不到您的 Controller 类。您是否正确注册了名为 Music\\V1\\Rest\\Albumjson\\Controller 的 Controller ?

关于php - 如何创建其他连接 zf2 apigility?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35021880/

相关文章:

php - 我的查询是否锁定该行以供下次使用

php - 使用 javascript 将值传递到另一个页面

mysql - 如何一次性修改mariadb图表集?

php - mysql 日期时间在 php 页面上显示不同

php - 如何在zf2 AbstractRestfulController中调用模板文件

php - 对表中 4 列的数组进行排序,以便按每列的字母顺序读取

javascript - 学生已存在注册系统验证 (Codeigniter)

mysql - 使用nodejs将多个复选框选择插入Mysql

php - 让事件在后台更改变量

php - 如何包含扩展接口(interface)的 php 类