简体   繁体   English

Zend_DB_Table_Abstract中的关系

[英]Relationships in Zend_DB_Table_Abstract

I'm using the default framework code that was created with the Zend Framework Application tool, I added some autoloader magic so that any classes named Default_<*>_<*> would automatically be loaded from the correct directory, in this case Default_Model_TableName . 我使用的是使用Zend Framework Application工具创建的默认框架代码,我添加了一些自动加载器魔术,以便任何名为Default_<*>_<*>都可以从正确的目录(在本例中为Default_Model_TableName自动加载。

application/models/ProjectCategories.php: 应用程序/模型/ProjectCategories.php:

<?php

class Default_Model_ProjectCategories extends Zend_Db_Table_Abstract {
    protected $_name = 'categories';
    protected $_dependentTables = array('Projects');
}

application/models/Projects.php: application / models / Projects.php:

<?php

class Default_Model_Projects extends Zend_Db_Table_Abstract {
    protected $_name = 'projects';

    protected $_referenceMap    = array(
        'Category' => array(
            'columns'           => 'cid',
            'refTableClass'     => 'ProjectCategories',
            'refColumns'        => 'id',
            'onUpdate'          => self::CASCADE,
            'onDelete'          => self::CASCADE,
        )
    );

}

What I am attempting to do is the following: 我正在尝试做以下事情:

<?php
$categories = new Default_Model_ProjectCategories();
$category = $categories->find('1');
$category->findProjects();

At which point I get an error thrown at me that it is unable to find Projects.php, and or that the file might not have contained a class named Projects. 此时,我遇到一个错误,即它找不到Projects.php,或者该文件可能未包含名为Projects的类。

At that point I place Projects.php in the include path that was set up by the framework (/../library/) and the file is found, but now I lose my whole directory structure, and naming because I had to rename Default_Model_Projects to Projects . 那时,我将Projects.php放置在框架(/../library/)设置的包含路径中,并且找到了文件,但是现在我失去了整个目录结构,并命名,因为我必须重命名Default_Model_ProjectsProjects I am able to get everything to work if I place the file back in its original location, and change 如果将文件放回原来的位置并进行更改,则可以使一切正常工作

protected $_dependentTables = array('Projects');

to

protected $_dependentTables = array('Default_Model_Projects');

but this also means that my ->findProjects() now becomes ->findDefault_Model_Projects() . 但这也意味着我的->findProjects()现在变为->findDefault_Model_Projects()

Is there a way to tell it that when I am looking for findProjects() that it has to instantiate Default_Model_Projects ? 有没有办法告诉我,当我寻找findProjects()时必须实例化Default_Model_Projects Is this something that is missing from Zend Framework, or am I attempting to shoehorn something in a way that it does not belong? 这是Zend Framework缺少的东西,还是我试图以某种不属于自己的方式来拔毛刺? How have you solved this issue? 您如何解决这个问题?

This problem may have been introduced by the new Autoloader, and the way in which it prefers to load namespaced classes (eg those prefixed as you have ). 新的Autoloader可能已经引入了此问题,并且它更喜欢加载命名空间的类(例如,带有前缀的类)。

In my applications I simply name models like 'Projects' and add a separate models folder to the include path for that application. 在我的应用程序中,我只是简单地命名诸如“ Projects”之类的模型,并在该应用程序的包含路径中添加一个单独的models文件夹。 This is one solution - unfortunately I don't know how you can make the namespaced models load correctly, but I would suggest looking at Zend_Loader in greater detail, and possible the pluginLoaders. 这是一个解决方案-不幸的是,我不知道如何使命名空间模型正确加载,但是我建议更详细地研究Zend_Loader,以及pluginLoaders。

i used to be able to do something like 我曾经能够做类似的事情

$resourceLoader = new Zend_Loader_Autoloader_Resource(array(
    'basePath'  => APPLICATION_PATH,
    'namespace' => 'App',
));
$resourceLoader->addResourceType('model', 'models/', '');

to shrink my model classes to App_TableName but seems like its not working now... 缩小我的模型类到App_TableName,但似乎它现在不起作用...

Change 更改

protected $_dependentTables = array('Projects');

to

protected $_dependentTables = array('Default_Model_Projects');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM