Kohana ORM:数组到字符串转换错误

时间:2021-10-20 16:27:28

I tried using Kohana/ORM on my localhost xampp and i get the following error

我尝试在我的localhost xampp上使用Kohana / ORM,我收到以下错误

ErrorException [ Notice ]: Array to string conversion MODPATH\orm\classes\kohana\orm.php [ 980 ]

ErrorException [注意]:数组到字符串转换MODPATH \ orm \ classes \ 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         }

It seems to be a common error appearing in different Frameworks/PHP Applications, but I have not found any clue to fix it.

它似乎是出现在不同的Frameworks / PHP应用程序中的常见错误,但我没有找到任何修复它的线索。

The Model is just the basic ORM

模型只是基本的ORM

class Model_Product extends ORM {

}

The Mysql Table (InnoDB - UTF-8) has two fields id - primary int name - varchar 50

Mysql表(InnoDB - UTF-8)有两个字段id - primary int name - varchar 50

no voodoo anywhere, help is very appreciated

没有伏都教任何地方,非常感谢帮助

thanks in advance!

提前致谢!

edit: the requested vardump

编辑:请求的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"
  }
}

2 个解决方案

#1


1  

Line 980:

980行:

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

looks superfluous taken the previous line 979 into account:

看起来多余的考虑到前一行979考虑:

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

Merging two times the same array is useless, especially as the array is this:

合并两次相同的数组是没用的,特别是因为数组是这样的:

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"
  }
}

It only contains string keys. You should open a bug report with the kohana framework.

它只包含字符串键。您应该使用kohana框架打开错误报告。

Comment line 980 until this get's fixed.

评论第980行,直到这个问题得到解决。

#2


0  

I found a way to resolve this error, just declare the table colums in the model.

我找到了解决此错误的方法,只需在模型中声明表colums。

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

this will ged rid of the problem and increase performance as well.

这样可以解决问题并提高性能。

#1


1  

Line 980:

980行:

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

looks superfluous taken the previous line 979 into account:

看起来多余的考虑到前一行979考虑:

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

Merging two times the same array is useless, especially as the array is this:

合并两次相同的数组是没用的,特别是因为数组是这样的:

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"
  }
}

It only contains string keys. You should open a bug report with the kohana framework.

它只包含字符串键。您应该使用kohana框架打开错误报告。

Comment line 980 until this get's fixed.

评论第980行,直到这个问题得到解决。

#2


0  

I found a way to resolve this error, just declare the table colums in the model.

我找到了解决此错误的方法,只需在模型中声明表colums。

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

this will ged rid of the problem and increase performance as well.

这样可以解决问题并提高性能。