Zend 从同一目录自动加载不同的命名空间?
我的项目中有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是因为 Table_User 中的 _ 。自动加载器可能正在寻找:
尝试将文件重命名为
将类重命名为:
或者创建
Table
文件夹并将 User.php 放入其中。Its because of the _ in Table_User. The autoloader is probably looking for:
Try renaming the file to
And the class to:
Or create the
Table
folder and put User.php in there.这是我自己做的事情。
我的“Model_”位于“{APPLICATION_PATH}/models/”中,“DbTable_”位于“{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/'.
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! :)