【问题标题】:PHP Doctrine relationship with namespacesPHP 原则与命名空间的关系
【发布时间】:2010-12-20 16:09:30
【问题描述】:

我刚开始使用 PHP 命名空间。我在不同的文件中有两个模型类

首先在两个文件中声明命名空间

命名空间 eu\ed\sixImport\importViewer\models;

头等舱:

类日志扩展\Doctrine_Record

    $this->hasMany('eu\ed\sixImport\importViewer\models\DataSource as DataSource', array(
        'local' => 'id',
        'foreign' => 'logId'));//setup relationship in setUp method

二等:

类 DataSource 扩展 \Doctrine_Record

    $this->hasOne('eu\ed\sixImport\importViewer\models\Log as Log', array(
        'local' => 'logId',
        'foreign' => 'id'));//setup relationship in setUp method

一切正常,直到我做出这样的事情

    $query = \Doctrine_Query::create()
        ->select('log.*')
        ->from('eu\ed\sixImport\importViewer\models\Log log')
        ->leftJoin("log.DataSource")
        ->orderBy("log.id DESC");

    $requiredPage = (($startingRow - ($startingRow%$rowsRequired))/$rowsRequired) + 1;
    $pager = new \Doctrine_Pager($query, $requiredPage, $rowsRequired);
    $res = $pager->execute();        
    $this->logsPageCount = $pager->getNumResults();
    print_r($res[0]["DataSource"]->toArray());//it fails on access to relationship

比 Doctrine 抛出异常 在 C:\wamp\www\importViewer\resources\doctrine\Doctrine-1.1.5\lib\Doctrine\Table.php:293...

从异常中,你可以看到,它寻找类 'eu\ed'。反斜杠[s] 剪切了类名的其余部分,并且没有明显找到类。你能给我一些建议,如何解决这个问题?

谢谢

【问题讨论】:

  • 两件事;一、你的PHP版本是多少?二,尝试使用双引号和双反斜杠。它不应该有所作为,但你永远不会知道。

标签: php namespaces doctrine


【解决方案1】:

我不确定 Doctrine 1 是否支持命名空间。我真的推荐使用 Doctrine 2 - 它建立在成熟的架构之上(使用 Java Hibernate 的 API),并且不像 Doctrine 1 那样涉及那么多魔法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-15
    • 1970-01-01
    • 2011-03-03
    • 2011-12-30
    • 1970-01-01
    • 2014-04-14
    相关资源
    最近更新 更多