Gas ORM - 自动创建表显示错误消息

时间:2016-10-07 10:21:38

标签: php codeigniter web orm frameworks

使用Gas ORM for CodeIgniter。

像在http://gasorm-doc.taufanaditya.com/configuration.html

中所说的那样

Gas ORM支持自动创建表格。这意味着您可以将现有的Gas模型转换为数据库。出于安全原因,默认情况下禁用此选项。启用:

$config['auto_create_tables'] = TRUE;

然后我在migration.php中启用迁移,然后在名为user.php和blog.php的models文件夹中创建2个类。代码如下:

用户类:

<?php

namespace Model;

use \Gas\Core;
use \Gas\ORM;

class User extends ORM {

    public $primary_key = 'id';

    function _init()
    {

            self::$relationships = array (
                    'blog'          =>     ORM::has_many('\\Model\\Blog');
            );

            self::$fields = array(
                    'id'                    =>              ORM::field('auto[10]'),
                    'username'              =>              ORM::field('char[64]'),
                    'password'              =>              ORM::field('char[255]'),
                    'email'                 =>              ORM::field('char[255]'),
            );
    }

}

Blogclass:

<?php namespace Model;

use \Gas\Core;
use \Gas\ORM;

class Blog extends ORM {

    public $primary_key = 'id';

    function _init()
    {

            self::$relationships = array (
                    'user'                  =>     ORM::belongs_to('\\Model\\User')
            );

            self::$fields = array(
                    'id'                    =>              ORM::field('auto[10]'),
                    'title'                 =>              ORM::field('char[255]', array('required','max_length[255]')),
                    'body'                  =>              ORM::field('string'),
                    'modified_at'           =>              ORM::field('datetime'),
                    'created_at'            =>              ORM::field('datetime'),
            );

            $this->ts_fields = array('modified_at','[created_at]');
    }

}

当我刷新页面时,页面显示错误:

A PHP Error was encountered

Severity: Runtime Notice

Message: Only variables should be passed by reference

Filename: classes/core.php

Line Number: 2460

Backtrace:

File: /application/third_party/gas/classes/core.php
Line: 2460
Function: _error_handler

File: /application/third_party/gas/classes/core.php
Line: 320
Function: _generate_tables

File: /application/third_party/gas/classes/core.php
Line: 360
Function: __construct

File: /application/third_party/gas/bootstrap.php
Line: 229
Function: make

File: /application/libraries/Gas.php
Line: 111
Function: include_once

File: /application/controllers/Home_Controller.php
Line: 7
Function: __construct

File: /index.php
Line: 315
Function: require_once

我真的坚持这个错误。任何人都可以帮我解决我的问题吗?

1 个答案:

答案 0 :(得分:0)

我已经跟踪了我的代码,问题类似于此引用:Only variables should be passed by reference

这个问题的事实可能是代码在运行时显示错误,但实际上代码完全是它的功能。所以我决定打开$ config [&#39; auto_create_tables&#39;] = TRUE;到$ config [&#39; auto_create_tables&#39;] = FALSE;使用此功能后。