【问题标题】:Zend 1.12 - autoloading models without Model_ NamespaceZend 1.12 - 自动加载没有 Model_ Namespace 的模型
【发布时间】:2014-01-08 22:27:25
【问题描述】:

我正在使用标准的开箱即用 Zend 1 目录结构并有一个模型:

applications
    /models
       /Menu
          Core.php

现在我想自动加载 Core,但不必将类命名为 Model_Menu_Core,而只是 Menu_Core,类似于从库目录中命名 Zend 库的方式,即 Zend_xxxx 而不是 Library_Zend_....

我真的不想单独注册每个命名空间,只是有类似于标准 PHP __autoload() 的自动自动加载

另外,我怎样才能为全局库目录实现同样的效果

我怎样才能做到这一点?谢谢

【问题讨论】:

  • 使用spl_autoload_register()

标签: zend-framework model zend-autoloader


【解决方案1】:

使用Zend_Loader_Autoloader_Resource并添加不带命名空间的资源类型,例如:

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
    /* ... */

    protected function _initAutoloaderResource()
    {
        $resourceLoader = new Zend_Loader_Autoloader_Resource(array(
            'namespace' => '',
            'basePath'  => APPLICATION_PATH));
        $resourceLoader->addResourceType('model', 'models/', '');
    }

    /* ... */
}

【讨论】:

    猜你喜欢
    • 2014-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-18
    • 2011-01-07
    • 2011-05-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多