Zend 从同一目录自动加载不同的命名空间?

发布于 2024-10-09 11:49:03 字数 509 浏览 0 评论 0原文

我的项目中有一个 models 目录,我想用不同的命名空间保存/文件类。 示例:

models/User.php with classname Model_User
models/Table_User.php with classname Model_Table_User

对于第一个命名空间,我在 bootstrap.php 中有这个,

$resourceLoader->addResourceTypes(array(
    'model' => array(
    'namespace' => 'Model',
    'path' => 'models'
    )
));

我不知道如何添加第二个命名空间,以便它检测以 Table_ 开头的文件 有什么想法吗?

现在,我添加了第二个名为“tables”的目录,但它变得令人困惑,因为每个模型名称都有两次(一次在模型目录中,一次在表目录中)

I have a models directory in my project, and I would like to save/files classes there with different namespaces.
Example:

models/User.php with classname Model_User
models/Table_User.php with classname Model_Table_User

For the first namespace I have this in bootstrap.php

$resourceLoader->addResourceTypes(array(
    'model' => array(
    'namespace' => 'Model',
    'path' => 'models'
    )
));

I can't figure out how to add the second namespace so it detects files starting with Table_ Any ideas?

For now I've added a second directory named 'tables' but it's getting confusing because I have each model name twice (once in the models diretory and once in the tables directory)

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

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

发布评论

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

评论(2

甩你一脸翔 2024-10-16 11:49:03

这是因为 Table_User 中的 _ 。自动加载器可能正在寻找:

models/Table/User.php

尝试将文件重命名为

TableUser.php

将类重命名为:

Model_TableUser

或者创建 Table 文件夹并将 User.php 放入其中。

Its because of the _ in Table_User. The autoloader is probably looking for:

models/Table/User.php

Try renaming the file to

TableUser.php

And the class to:

Model_TableUser

Or create the Table folder and put User.php in there.

盗琴音 2024-10-16 11:49:03

这是我自己做的事情。
我的“Model_”位于“{APPLICATION_PATH}/models/”中,“DbTable_”位于“{APPLICATION_PATH}/models/dbtables/”中。


$resourceLoader->addResourceTypes(array(
    'model' => array(
    'namespace' => 'Model_',
    'path' => APPLICATION_PATH.'/models/'
    ),
    'dbtable' => array(
    'namespace' => 'DbTable_',
    'path' => APPLICATION_PATH.'/models/dbtables/'
));

您当然应该根据您的类名和文件夹结构修改它。
APPLICATION_PATH 在您的 index.php 中定义 - 但我不记得它是否包含尾部斜杠,因此请检查以防万一。 (我现在不在我的电脑上,所以我无法检查...)

就这么简单! :)

That's something I do myself.
I have "Model_" sat in '{APPLICATION_PATH}/models/' and "DbTable_" sat in '{APPLICATION_PATH}/models/dbtables/'.


$resourceLoader->addResourceTypes(array(
    'model' => array(
    'namespace' => 'Model_',
    'path' => APPLICATION_PATH.'/models/'
    ),
    'dbtable' => array(
    'namespace' => 'DbTable_',
    'path' => APPLICATION_PATH.'/models/dbtables/'
));

You should of course modify this to according to your classnames and folder structure.
APPLICATION_PATH is defined in your index.php -- but I don't remember if it contains a trailing slash, so check that just in case. (I'm not on my pc at the moment so I cannot check...)

Simple as that! :)

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