【发布时间】:2017-02-16 07:39:45
【问题描述】:
在 CodeIgniter 中使用 Gas ORM。
就像在http://gasorm-doc.taufanaditya.com/configuration.html中所说的那样
Gas ORM 支持自动创建表。这意味着您可以将现有的 Gas 模型转换为数据库。出于安全原因,默认情况下禁用此选项。要启用:
$config['auto_create_tables'] = TRUE;
然后我在 migration.php 中启用迁移,然后在名为 user.php 和 blog.php 的模型文件夹中创建 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]'),
);
}
}
博客类:
<?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
我真的遇到了这个错误。谁能帮我解决我的问题?
【问题讨论】:
-
第 7 行的 Home_Controller.php 中有什么?
-
@Tpojka :它是一个控制器文件,用于处理或调用视图(在本例中是一个名为 homeview 的 php 文件)。用于这样调用的代码 $this->load->view('homeview'); . homeview 是 php 文件,目前只包含 HTML 代码。
-
您能否在错误消息中看到由于该文件的第 7 行而发现的第一个错误?请也发布有问题的文件代码。
标签: php codeigniter web orm frameworks