0

我在 Code Igniter 中有一个带有 HMVC 扩展的现有项目。还通过 sparc 使用 php-activerecord。

对于一个新模块,我创建了两个具有一对多关系的表,直接在数据库级别(在 MySQL 中)强制执行。表格是“nassignment”(PK id)和“nassignment_assignee”(FK assignment_id)。

在模型下,我创建了两个具有类 Nassignment 的类“nassignment.php”和类名为 Nassignment_assignee 的“nassignment_assignee.php”。

下面是我在控制器中尝试的代码

$this->load->model("nassignment");
$nAssignmentArr = $this->nassignment->all();

并出现以下错误

[Fri Aug 02 13:50:52 2013] [error] [client 127.0.0.1] PHP Fatal error:  Uncaught 
exception 'ReflectionException' with message 'Class Nassignmentassignee does not exist' 
in /home/kapil/projects/<project>/application/sparks/php-activerecord/0.0.2/vendor/php-
activerecord/lib/Reflections.php:33\nStack trace:\n#0 
/home/kapil/projects/<project>/application/sparks/php-activerecord/0.0.2/vendor/php-
activerecord/lib/Reflections.php(33): ReflectionClass-
>__construct('Nassignmentassi...')\n#1 
/home/kapil/projects/<project>/application/sparks/php-activerecord/0.0.2/vendor/php-
activerecord/lib/Relationship.php(286): ActiveRecord\\Reflections-
>add('Nassignmentassi...')\n#2 /home/kapil/projects/<project>/application/sparks/php-
activerecord/0.0.2/vendor/php-activerecord/lib/Relationship.php(281): 
ActiveRecord\\AbstractRelationship->set_class_name('Nassignmentassi...')\n#3 
/home/kapil/projects/<project>/application/sparks/php-activerecord/0.0.2/vendor/php-
activerecord/lib/Relationship.php(464): ActiveRecord\\AbstractRelationship-
>set_inferred_class_name()\n#4 /home/kapil/projects/<project>/application/sparks/php-
activerecord/0.0 in /home/kapil/projects/<project>/application/sparks/php-
activerecord/0.0.2/vendor/php-activerecord/lib/Reflections.php on line 33

型号代码是

nassignment.php

class Nassignment Extends ActiveRecord\Model{
    static $table_name = 'nassignment';
    //Work fine if I remove following line, but do not get data
    static $has_many = array(
            array('nassignment_assignee')
        );
}

nassignment_assignee.php

class Nassignment_assignee Extends ActiveRecord\Model{
    static $table_name = 'nassignment_assignee';
}

任何建议,为什么它不起作用

4

1 回答 1

1

尝试确保文件名与类名匹配,以防万一。查看我的问题的解决方案

显然,库也必须根据 UCfirst 命名约定来命名。

于 2013-10-08T05:06:06.260 回答