douxuanyi2813 2013-04-14 18:03
浏览 38
已采纳

Zend Db Table从另一个模块的引用表中获取行

I am currently working an a Zend framework 1.12 based project. I use different modules to keep things separated as good as possible. My data is stored in a mysql database so I set up some db table models inside my project. The relation between the tables should be handled by Zend frameworks Zend_Db_Table Relationships. I added the necessary code to my classes:

class User_Model_DbTable_Users extends Zend_Db_Table_Abstract
{
    protected $_name = 'users';
    protected $_primary = 'user_id';

    protected $_dependentTables = array('Diagnostics_Model_DbTable_Diagnostics');
}

User_Model_DbTable_Users is the parent class and is defined inside the Users module. Diagnostics_Model_DbTable_Diagnostics is the referenced class and is defined inside the Diagnostics module.

class Diagnostics_Model_DbTable_Diagnostics extends Zend_Db_Table_Abstract
{
    protected $_name = 'diagnostics';
    protected $_primary = 'diagnostic_id';

    protected $_referenceMap = array(
        'User' => array(
            'columns'   =>  array('diagnostic_user'),
            'refTableClass' =>  'User_Model_DbTable_Users',
            'refColumns'    =>  array('user_id')
        )
    );
}

When I now try to load the referenced Diagnostics for a User row using

$row->findDiagnostics_Model_DbTable_Diagnostics();

I get an error:

File "Diagnostics\Model\DbTable\Diagnostics.php" does not exist or class "Diagnostics_Model_DbTable_Diagnostics" was not found in the file

When I move the class Diagnostics_Model_DbTable_Diagnostics into the Users module and rename it correspondingly everthing works fine. So it seems to me as if it has something to do with classes beeing defined in different modules. None of the articles I have found during my researches could give me an answer to this. Maybe I am missing something in the main Bootstrap.php or the application.ini.

  • 写回答

1条回答 默认 最新

  • douyuai8994 2013-04-15 07:40
    关注

    You will need to bootstrap the module. Good info: http://akrabat.com/zend-framework/bootstrapping-modules-in-zf-1-8/

    I use a simple class as below:

    class Diagnostics_Bootstrap extends Zend_Application_Module_Bootstrap {
         ...
    }
    

    Don't bootstrap modules you don't need, I suggest reading http://www.mwop.net/blog/234-Module-Bootstraps-in-Zend-Framework-Dos-and-Donts.html

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么