从 Zend_Db::factory() 加载 Zend_Test_DbAdapter

发布于 2024-12-03 22:32:07 字数 1413 浏览 3 评论 0 原文

如何获取 Zend Framework 使用 href="http://framework.zend.com/manual/en/zend.db.adapter.html#zend.db.adapter.connecting.factory" rel="nofollow">Zend_Db::factory()

我有以下代码,但工厂在我的适配器外壳上标记并破坏了文件路径。有点讽刺的是,他们的测试适配器无法由他们自己的工厂加载。我在这里做错了什么?

$config = new Zend_Config(
    array(
        'database' => array(
            'adapter' => 'DbAdapter',
            'params' => array(
                'adapterNamespace' => 'Zend_Test',
                'host' => 'localhost',
                'dbname' => 'mydb',
                'username' => 'not',
                'password' => 'needed'
            )
        )
    )
);

$db = Zend_Db::factory($config->database);

我收到以下错误:

Zend_Loader::include_once(Zend/Test/Dbadapter.php): failed to open stream: No such file or directory

已更新

上面的代码是直接复制和粘贴的,适配器参数大小写正确:“DbAdapter”。这与文件案例 Zend_Test_DbAdapter 匹配。

我更改了代码以手动实例化 Zend_Test_DbAdapter 并且它可以毫无问题地自动加载。

$db = new Zend_Test_DbAdapter;
print_r(get_class($db));

输出:

Zend_Test_DbAdapter

我仍然相信 Zend_Db::factory() 方法正在削弱我的适配器字符大小写,将第一个字符大写,将其余字符小写。

How can I obtain and instance of the Zend Framework Test DbAdapter using the Zend_Db::factory()?

I have the following code but the Factory stamps on my adapter case and breaks the file path. It seems a little ironic their test adapter can't be loaded by their own Factory. What am I doing wrong here?

$config = new Zend_Config(
    array(
        'database' => array(
            'adapter' => 'DbAdapter',
            'params' => array(
                'adapterNamespace' => 'Zend_Test',
                'host' => 'localhost',
                'dbname' => 'mydb',
                'username' => 'not',
                'password' => 'needed'
            )
        )
    )
);

$db = Zend_Db::factory($config->database);

I get the following error:

Zend_Loader::include_once(Zend/Test/Dbadapter.php): failed to open stream: No such file or directory

Updated

The code above is a direct copy and paste, the adapter parameter case is correct: 'DbAdapter'. This matches the file case Zend_Test_DbAdapter.

I changed my code to manually instantiate Zend_Test_DbAdapter and it autoloads without issue.

$db = new Zend_Test_DbAdapter;
print_r(get_class($db));

Output:

Zend_Test_DbAdapter

I still believe the Zend_Db::factory() method is nerfing my adapter character case, upper casing the first character, lower casing the rest.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

傲世九天 2024-12-10 22:32:07

检查拼写错误

if not 'adapter' => 'Dbadapter', to 'adapter' => 'DbAdapter',

Zend/Test/Dbadapter.php does not exits
Zend/Test/DbAdapter.php exits in library 

文件丢失

您必须在 includePath 中添加 zend lib,或者如果它是 zend 项目,则将 zend 文件添加到库

/应用程序 中
/图书馆
添加 Zend 文件(从 http://framework.zend.com/download 下载)

Check Typo mistake

if not 'adapter' => 'Dbadapter', to 'adapter' => 'DbAdapter',

Zend/Test/Dbadapter.php does not exits
Zend/Test/DbAdapter.php exits in library 

OR

File is Missing

You have to add zend lib in includePath or if its a zend project add zend files into library

/application
/library
add Zend files (download from http://framework.zend.com/download)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文