Zend是否从同一个目录中自动加载了不同的名称空间? [英] Zend autloading different namespaces from the same directory?

查看:47
本文介绍了Zend是否从同一个目录中自动加载了不同的名称空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目中有一个models目录,我想用不同的名称空间在其中保存/归档类. 示例:

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

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

For the first namespace I have this in bootstrap.php

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

我不知道如何添加第二个命名空间,因此它可以检测以Table_开头的文件吗?

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

现在,我添加了第二个名为"tables"的目录,但由于每个模型名称都有两次(在模型目录中一次,在表目录中一次),因此令人困惑.

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)

推荐答案

那是我自己做的事情.
我的"Model_"坐在"{APPLICATION_PATH}/models/"中,"DbTable_"在"{APPLICATION_PATH}/models/dbtables/"中.

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/'
));

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

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...)

就这么简单! :)

这篇关于Zend是否从同一个目录中自动加载了不同的名称空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆