2011-12-01 23 views
2

我在我的本地XAMPP使用的Kohana/ORM试过,我得到以下错误Kohana的ORM:数组字符串转换错误

ErrorException [公告]:数组字符串转换 MODPATH \ ORM \类\ Kohana的\ ORM .PHP [980]

975    } 
976    else 
977    { 
978     // List columns and mirror for performance 
979     $this->_table_columns = $this->list_columns(); 
980     $this->_table_columns = array_combine($this->_table_columns, $this->_table_columns); 
981 
982     // Load column cache 
983     ORM::$_column_cache[$this->_object_name] = $this->_table_columns; 
984    } 
985   } 

这似乎是出现在不同的框架/ PHP应用程序的常见错误,但我还没有发现任何线索来解决它。

模型仅仅是基本的ORM

class Model_Product extends ORM { 

} 

MySQL表(InnoDB的 - UTF-8)有两个字段 ID - 初级INT 名字 - VARCHAR 50

没有巫术的任何地方,帮助非常感谢

在此先感谢!

编辑:请求vardump

array(2) { 
    ["id"]=> 
    array(13) { 
    ["type"]=> 
    string(3) "int" 
    ["min"]=> 
    string(11) "-2147483648" 
    ["max"]=> 
    string(10) "2147483647" 
    ["column_name"]=> 
    string(2) "id" 
    ["column_default"]=> 
    NULL 
    ["data_type"]=> 
    string(3) "int" 
    ["is_nullable"]=> 
    bool(false) 
    ["ordinal_position"]=> 
    int(1) 
    ["display"]=> 
    string(2) "11" 
    ["comment"]=> 
    string(0) "" 
    ["extra"]=> 
    string(14) "auto_increment" 
    ["key"]=> 
    string(3) "PRI" 
    ["privileges"]=> 
    string(31) "select,insert,update,references" 
    } 
    ["name"]=> 
    array(12) { 
    ["type"]=> 
    string(6) "string" 
    ["column_name"]=> 
    string(4) "name" 
    ["column_default"]=> 
    NULL 
    ["data_type"]=> 
    string(7) "varchar" 
    ["is_nullable"]=> 
    bool(false) 
    ["ordinal_position"]=> 
    int(2) 
    ["character_maximum_length"]=> 
    string(2) "50" 
    ["collation_name"]=> 
    string(15) "utf8_general_ci" 
    ["comment"]=> 
    string(0) "" 
    ["extra"]=> 
    string(0) "" 
    ["key"]=> 
    string(0) "" 
    ["privileges"]=> 
    string(31) "select,insert,update,references" 
    } 
} 
+0

请将'var_dump($ this-> list_columns())'添加到您的问题中。 – hakre

+0

添加了vardump – rootman

+0

您使用的是什么版本? – Kowser

回答

0

我发现了一种解决此错误的方法,只需在模型中声明表格列。

protected $_table_columns = array(
    'column' => NULL, 
    'names' => NULL, 
    'go'  => NULL, 
    'here' => NULL, 
    ...... 
); 

这将消除问题并提高性能。

1

行980:

980     $this->_table_columns = array_combine($this->_table_columns, $this->_table_columns); 

看起来多余前行979考虑:

979     $this->_table_columns = $this->list_columns(); 

合并两次同样的阵列无用的,特别是当数组是这样的:

array(2) { 
    ["id"]=> 
    array(13) { 
    ["type"]=> 
    string(3) "int" 
    ["min"]=> 
    string(11) "-2147483648" 
    ["max"]=> 
    string(10) "2147483647" 
    ["column_name"]=> 
    string(2) "id" 
    ["column_default"]=> 
    NULL 
    ["data_type"]=> 
    string(3) "int" 
    ["is_nullable"]=> 
    bool(false) 
    ["ordinal_position"]=> 
    int(1) 
    ["display"]=> 
    string(2) "11" 
    ["comment"]=> 
    string(0) "" 
    ["extra"]=> 
    string(14) "auto_increment" 
    ["key"]=> 
    string(3) "PRI" 
    ["privileges"]=> 
    string(31) "select,insert,update,references" 
    } 
    ["name"]=> 
    array(12) { 
    ["type"]=> 
    string(6) "string" 
    ["column_name"]=> 
    string(4) "name" 
    ["column_default"]=> 
    NULL 
    ["data_type"]=> 
    string(7) "varchar" 
    ["is_nullable"]=> 
    bool(false) 
    ["ordinal_position"]=> 
    int(2) 
    ["character_maximum_length"]=> 
    string(2) "50" 
    ["collation_name"]=> 
    string(15) "utf8_general_ci" 
    ["comment"]=> 
    string(0) "" 
    ["extra"]=> 
    string(0) "" 
    ["key"]=> 
    string(0) "" 
    ["privileges"]=> 
    string(31) "select,insert,update,references" 
    } 
} 

它只包含字符串键。你应该用kohana框架打开一个bug报告。

评论栏980直到这个得到修正。

+0

你是对的,该行只是...没用,但是当这样做时,弹出第二个错误,同样的错误,但这次在931行:$ values = array_combine($ this - > _ table_columns,array_fill(0, count($ this - > _ table_columns),NULL));我想我会把这个问题报告给kohana,看看他们能做些什么 – rootman

+0

这样多余的观察线的问题是它们包含一些考古学信息,正如你所看到的那样 - 隐藏缺陷。从你所描述的,'$ this - > _ table_columns'在某些情况下不包含数组。正如我期望的那样,我几乎不会在第980行中拯救'if(!is_array($ this - > _ table_columns))抛出新的UnexpectedValueException('不是数组');' - 然后你会得到一个致命的错误,它可以防止将应用程序置于未定义的状态。这也可能有助于通过回溯来找到造成这种情况的原因。 – hakre

+0

我在http://dev.kohanaframework.org/issues/4352创建了一个问题。我认为这是一个应该尽快解决的问题,因为如果你不想在核心文件中修补,它会阻止进一步的开发。 – rootman